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

refactor(typings): partial Types #3493

Merged
merged 13 commits into from Oct 11, 2019
109 changes: 68 additions & 41 deletions typings/index.d.ts
Expand Up @@ -159,33 +159,33 @@ declare module 'discord.js' {
public sweepMessages(lifetime?: number): number;
public toJSON(): object;

public on(event: 'channelCreate' | 'channelDelete', listener: (channel: Channel) => void): this;
public on(event: 'channelPinsUpdate', listener: (channel: Channel, time: Date) => void): this;
public on(event: 'channelUpdate', listener: (oldChannel: Channel, newChannel: Channel) => void): this;
public on(event: 'channelCreate' | 'channelDelete', listener: (channel: Channel | PartialChannel) => void): this;
public on(event: 'channelPinsUpdate', listener: (channel: Channel | PartialChannel, time: Date) => void): this;
public on(event: 'channelUpdate', listener: (oldChannel: Channel | PartialChannel, newChannel: Channel | PartialChannel) => void): this;
public on(event: 'debug' | 'warn', listener: (info: string) => void): this;
public on(event: 'disconnect', listener: (event: any, shardID: number) => void): this;
public on(event: 'emojiCreate' | 'emojiDelete', listener: (emoji: GuildEmoji) => void): this;
public on(event: 'emojiUpdate', listener: (oldEmoji: GuildEmoji, newEmoji: GuildEmoji) => void): this;
public on(event: 'error', listener: (error: Error) => void): this;
public on(event: 'guildBanAdd' | 'guildBanRemove', listener: (guild: Guild, user: User) => void): this;
public on(event: 'guildBanAdd' | 'guildBanRemove', listener: (guild: Guild, user: User | PartialUser) => void): this;
public on(event: 'guildCreate' | 'guildDelete' | 'guildUnavailable', listener: (guild: Guild) => void): this;
public on(event: 'guildMemberAdd' | 'guildMemberAvailable' | 'guildMemberRemove', listener: (member: GuildMember) => void): this;
public on(event: 'guildMembersChunk', listener: (members: Collection<Snowflake, GuildMember>, guild: Guild) => void): this;
public on(event: 'guildMemberSpeaking', listener: (member: GuildMember, speaking: Readonly<Speaking>) => void): this;
public on(event: 'guildMemberUpdate', listener: (oldMember: GuildMember, newMember: GuildMember) => void): this;
public on(event: 'guildMemberAdd' | 'guildMemberAvailable' | 'guildMemberRemove', listener: (member: GuildMember | PartialGuildMember) => void): this;
public on(event: 'guildMembersChunk', listener: (members: Collection<Snowflake, GuildMember | PartialGuildMember>, guild: Guild) => void): this;
public on(event: 'guildMemberSpeaking', listener: (member: GuildMember | PartialGuildMember, speaking: Readonly<Speaking>) => void): this;
public on(event: 'guildMemberUpdate', listener: (oldMember: GuildMember | PartialGuildMember, newMember: GuildMember | PartialGuildMember) => void): this;
public on(event: 'guildUpdate', listener: (oldGuild: Guild, newGuild: Guild) => void): this;
public on(event: 'guildIntegrationsUpdate', listener: (guild: Guild) => void): this;
public on(event: 'message' | 'messageDelete' | 'messageReactionRemoveAll', listener: (message: Message) => void): this;
public on(event: 'messageDeleteBulk', listener: (messages: Collection<Snowflake, Message>) => void): this;
public on(event: 'messageReactionAdd' | 'messageReactionRemove', listener: (messageReaction: MessageReaction, user: User) => void): this;
public on(event: 'messageUpdate', listener: (oldMessage: Message, newMessage: Message) => void): this;
public on(event: 'message' | 'messageDelete' | 'messageReactionRemoveAll', listener: (message: Message | PartialMessage) => void): this;
public on(event: 'messageDeleteBulk', listener: (messages: Collection<Snowflake, Message | PartialMessage>) => void): this;
public on(event: 'messageReactionAdd' | 'messageReactionRemove', listener: (messageReaction: MessageReaction, user: User | PartialUser) => void): this;
public on(event: 'messageUpdate', listener: (oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage) => void): this;
public on(event: 'presenceUpdate', listener: (oldPresence: Presence | undefined, newPresence: Presence) => void): this;
public on(event: 'rateLimit', listener: (rateLimitData: RateLimitData) => void): this;
public on(event: 'ready', listener: () => void): this;
public on(event: 'roleCreate' | 'roleDelete', listener: (role: Role) => void): this;
public on(event: 'roleUpdate', listener: (oldRole: Role, newRole: Role) => void): this;
public on(event: 'typingStart' | 'typingStop', listener: (channel: Channel, user: User) => void): this;
public on(event: 'userUpdate', listener: (oldUser: User, newUser: User) => void): this;
public on(event: 'typingStart' | 'typingStop', listener: (channel: Channel | PartialChannel, user: User | PartialUser) => void): this;
public on(event: 'userUpdate', listener: (oldUser: User | PartialUser, newUser: User | PartialUser) => void): this;
public on(event: 'voiceStateUpdate', listener: (oldState: VoiceState | undefined, newState: VoiceState) => void): this;
public on(event: 'webhookUpdate', listener: (channel: TextChannel) => void): this;
public on(event: 'invalidated', listener: () => void): this;
Expand All @@ -196,33 +196,33 @@ declare module 'discord.js' {
public on(event: 'shardResume', listener: (id: number, replayed: number) => void): this;
public on(event: string, listener: Function): this;

public once(event: 'channelCreate' | 'channelDelete', listener: (channel: Channel) => void): this;
public once(event: 'channelPinsUpdate', listener: (channel: Channel, time: Date) => void): this;
public once(event: 'channelUpdate', listener: (oldChannel: Channel, newChannel: Channel) => void): this;
public once(event: 'channelCreate' | 'channelDelete', listener: (channel: Channel | PartialChannel) => void): this;
public once(event: 'channelPinsUpdate', listener: (channel: Channel | PartialChannel, time: Date) => void): this;
public once(event: 'channelUpdate', listener: (oldChannel: Channel | PartialChannel, newChannel: Channel | PartialChannel) => void): this;
public once(event: 'debug' | 'warn', listener: (info: string) => void): this;
public once(event: 'disconnect', listener: (event: any, shardID: number) => void): this;
public once(event: 'emojiCreate' | 'emojiDelete', listener: (emoji: GuildEmoji) => void): this;
public once(event: 'emojiUpdate', listener: (oldEmoji: GuildEmoji, newEmoji: GuildEmoji) => void): this;
public once(event: 'error', listener: (error: Error) => void): this;
public once(event: 'guildBanAdd' | 'guildBanRemove', listener: (guild: Guild, user: User) => void): this;
public once(event: 'guildBanAdd' | 'guildBanRemove', listener: (guild: Guild, user: User | PartialUser) => void): this;
public once(event: 'guildCreate' | 'guildDelete' | 'guildUnavailable', listener: (guild: Guild) => void): this;
public once(event: 'guildMemberAdd' | 'guildMemberAvailable' | 'guildMemberRemove', listener: (member: GuildMember) => void): this;
public once(event: 'guildMembersChunk', listener: (members: Collection<Snowflake, GuildMember>, guild: Guild) => void): this;
public once(event: 'guildMemberSpeaking', listener: (member: GuildMember, speaking: Readonly<Speaking>) => void): this;
public once(event: 'guildMemberUpdate', listener: (oldMember: GuildMember, newMember: GuildMember) => void): this;
public once(event: 'guildMemberAdd' | 'guildMemberAvailable' | 'guildMemberRemove', listener: (member: GuildMember | PartialGuildMember) => void): this;
public once(event: 'guildMembersChunk', listener: (members: Collection<Snowflake, GuildMember | PartialGuildMember>, guild: Guild) => void): this;
public once(event: 'guildMemberSpeaking', listener: (member: GuildMember | PartialGuildMember, speaking: Readonly<Speaking>) => void): this;
public once(event: 'guildMemberUpdate', listener: (oldMember: GuildMember | PartialGuildMember, newMember: GuildMember | PartialGuildMember) => void): this;
public once(event: 'guildUpdate', listener: (oldGuild: Guild, newGuild: Guild) => void): this;
public once(event: 'guildIntegrationsUpdate', listener: (guild: Guild) => void): this;
public once(event: 'message' | 'messageDelete' | 'messageReactionRemoveAll', listener: (message: Message) => void): this;
public once(event: 'messageDeleteBulk', listener: (messages: Collection<Snowflake, Message>) => void): this;
public once(event: 'messageReactionAdd' | 'messageReactionRemove', listener: (messageReaction: MessageReaction, user: User) => void): this;
public once(event: 'messageUpdate', listener: (oldMessage: Message, newMessage: Message) => void): this;
public once(event: 'message' | 'messageDelete' | 'messageReactionRemoveAll', listener: (message: Message | PartialMessage) => void): this;
public once(event: 'messageDeleteBulk', listener: (messages: Collection<Snowflake, Message | PartialMessage>) => void): this;
public once(event: 'messageReactionAdd' | 'messageReactionRemove', listener: (messageReaction: MessageReaction, user: User | PartialUser) => void): this;
public once(event: 'messageUpdate', listener: (oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage) => void): this;
public once(event: 'presenceUpdate', listener: (oldPresence: Presence | undefined, newPresence: Presence) => void): this;
public once(event: 'rateLimit', listener: (rateLimitData: RateLimitData) => void): this;
public once(event: 'ready', listener: () => void): this;
public once(event: 'roleCreate' | 'roleDelete', listener: (role: Role) => void): this;
public once(event: 'roleUpdate', listener: (oldRole: Role, newRole: Role) => void): this;
public once(event: 'typingStart' | 'typingStop', listener: (channel: Channel, user: User) => void): this;
public once(event: 'userUpdate', listener: (oldUser: User, newUser: User) => void): this;
public once(event: 'typingStart' | 'typingStop', listener: (channel: Channel | PartialChannel, user: User | PartialUser) => void): this;
public once(event: 'userUpdate', listener: (oldUser: User | PartialUser, newUser: User | PartialUser) => void): this;
public once(event: 'voiceStateUpdate', listener: (oldState: VoiceState | undefined, newState: VoiceState) => void): this;
public once(event: 'webhookUpdate', listener: (channel: TextChannel) => void): this;
public once(event: 'invalidated', listener: () => void): this;
Expand Down Expand Up @@ -465,7 +465,7 @@ declare module 'discord.js' {
RESUMED: 'resumed';
};
PartialTypes: {
[K in PartialType]: K;
[K in PartialTypes]: K;
};
WSEvents: {
[K in WSEventType]: K;
Expand Down Expand Up @@ -627,7 +627,7 @@ declare module 'discord.js' {
constructor(client: Client, data?: object);
public messages: MessageStore;
public recipient: User;
public readonly partial: boolean;
public readonly partial: false;
}

export class Emoji extends Base {
Expand Down Expand Up @@ -836,12 +836,12 @@ declare module 'discord.js' {
public readonly displayName: string;
public guild: Guild;
public readonly id: Snowflake;
public readonly joinedAt: Date | null;
public joinedTimestamp: number | null;
public readonly joinedAt: Date;
public joinedTimestamp: number;
Copy link
Contributor

@Lewdcario Lewdcario Oct 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be marked as null, due to 13bfceb.
Explanation: #3533 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks for the explanation

public readonly kickable: boolean;
public readonly manageable: boolean;
public nickname: string;
public readonly partial: boolean;
public readonly partial: false;
public readonly permissions: Readonly<Permissions>;
public readonly premiumSince: Date | null;
public premiumSinceTimestamp: number | null;
Expand Down Expand Up @@ -922,7 +922,7 @@ declare module 'discord.js' {
public activity: GroupActivity | null;
public application: ClientApplication | null;
public attachments: Collection<Snowflake, MessageAttachment>;
public author: User | null;
public author: User;
public channel: TextChannel | DMChannel;
public readonly cleanContent: string;
public content: string;
Expand All @@ -940,7 +940,7 @@ declare module 'discord.js' {
public readonly member: GuildMember | null;
public mentions: MessageMentions;
public nonce: string;
public readonly partial: boolean;
public readonly partial: false;
public readonly pinnable: boolean;
public pinned: boolean;
public reactions: ReactionStore;
Expand Down Expand Up @@ -1370,7 +1370,7 @@ declare module 'discord.js' {
public readonly dmChannel: DMChannel;
public id: Snowflake;
public locale: string;
public readonly partial: boolean;
public readonly partial: false;
public readonly presence: Presence;
public readonly tag: string;
public username: string;
Expand Down Expand Up @@ -2461,6 +2461,38 @@ declare module 'discord.js' {
| 'GUILD_MEMBER'
| 'MESSAGE';

type PartialMessage = {
id: string;
partial: true;
fetch(): Promise<Message>;
} & {
[K in keyof Omit<Message, 'id' | 'partial'>]: Message[K] | null;
};

type PartialChannel = {
id: string;
partial: true;
fetch(): Promise<Channel>;
} & {
[K in keyof Omit<Channel, 'id' | 'partial'>]: Channel[K] | null;
};

type PartialGuildMember = {
id: string;
partial: true;
fetch(): Promise<GuildMember>;
} & {
[K in keyof Omit<GuildMember, 'id' | 'partial'>]: GuildMember[K] | null;
};

type PartialUser = {
id: string;
partial: true;
fetch(): Promise<User>;
} & {
[K in keyof Omit<User, 'id' | 'partial'>]: User[K] | null;
};

type PresenceStatus = ClientPresenceStatus | 'offline';

type PresenceStatusData = ClientPresenceStatus | 'invisible';
Expand Down Expand Up @@ -2567,11 +2599,6 @@ declare module 'discord.js' {
compress?: boolean;
}

type PartialType = 'USER'
| 'CHANNEL'
| 'GUILD_MEMBER'
| 'MESSAGE';

type WSEventType = 'READY'
| 'RESUMED'
| 'GUILD_CREATE'
Expand Down