Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types(Partials): add toString() method to supported Partials #9835

Merged
merged 11 commits into from
Oct 10, 2023
18 changes: 10 additions & 8 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6161,15 +6161,17 @@ export interface PartialChannelData {

export type Partialize<
T extends AllowedPartial,
N extends keyof T | null = null,
M extends keyof T | null = null,
E extends keyof T | '' = '',
NulledKeys extends keyof T | null = null,
NullableKeys extends keyof T | null = null,
OverridableKeys extends keyof T | '' = '',
> = {
readonly client: Client<true>;
id: Snowflake;
partial: true;
} & {
[K in keyof Omit<T, 'client' | 'id' | 'partial' | E>]: K extends N ? null : K extends M ? T[K] | null : T[K];
[K in keyof Omit<T, OverridableKeys>]: K extends 'partial'
? true
: K extends NulledKeys
? null
: K extends NullableKeys
? T[K] | null
: T[K];
};
janparisek marked this conversation as resolved.
Show resolved Hide resolved

export interface PartialDMChannel extends Partialize<DMChannel, null, null, 'lastMessageId'> {
Expand Down
40 changes: 40 additions & 0 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ import {
StringSelectMenuComponentData,
ButtonComponentData,
MediaChannel,
PartialDMChannel,
PartialGuildMember,
PartialMessage,
PartialMessageReaction,
} from '.';
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
Expand Down Expand Up @@ -2323,3 +2327,39 @@ expectType<Readonly<GuildMemberFlagsBitField>>(guildMember.flags);
const onboarding = await guild.fetchOnboarding();
expectType<GuildOnboarding>(onboarding);
}

declare const partialDMChannel: PartialDMChannel;
expectType<true>(partialDMChannel.partial);
expectType<undefined>(partialDMChannel.lastMessageId);

declare const partialGuildMember: PartialGuildMember;
expectType<true>(partialGuildMember.partial);
expectType<null>(partialGuildMember.joinedAt);
expectType<null>(partialGuildMember.joinedTimestamp);
expectType<null>(partialGuildMember.pending);

declare const partialMessage: PartialMessage;
expectType<true>(partialMessage.partial);
expectType<null>(partialMessage.type);
expectType<null>(partialMessage.system);
expectType<null>(partialMessage.pinned);
expectType<null>(partialMessage.tts);
expectAssignable<null | Message['content']>(partialMessage.content);
expectAssignable<null | Message['cleanContent']>(partialMessage.cleanContent);
expectAssignable<null | Message['author']>(partialMessage.author);

declare const partialMessageReaction: PartialMessageReaction;
expectType<true>(partialMessageReaction.partial);
expectType<null>(partialMessageReaction.count);

declare const partialThreadMember: PartialThreadMember;
expectType<true>(partialThreadMember.partial);
expectType<null>(partialThreadMember.flags);
expectType<null>(partialThreadMember.joinedAt);
expectType<null>(partialThreadMember.joinedTimestamp);

declare const partialUser: PartialUser;
expectType<true>(partialUser.partial);
expectType<null>(partialUser.username);
expectType<null>(partialUser.tag);
expectType<null>(partialUser.discriminator);