From cbb33ecdacdb8fe106c23ccd37d990da6e1b946e Mon Sep 17 00:00:00 2001 From: Danial Raza Date: Fri, 21 Feb 2025 16:11:07 +0100 Subject: [PATCH] types(InteractionCallbackResponse): add missing `InGuild` generic (#10767) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: TÆMBØ Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/discord.js/typings/index.d.ts | 78 +++++++++++++-------- packages/discord.js/typings/index.test-d.ts | 68 +++++++++--------- 2 files changed, 84 insertions(+), 62 deletions(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 1a37649fb..73167dc03 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -571,27 +571,31 @@ export abstract class CommandInteraction e public inRawGuild(): this is CommandInteraction<'raw'>; public deferReply( options: InteractionDeferReplyOptions & { withResponse: true }, - ): Promise; + ): Promise>>; public deferReply(options?: InteractionDeferReplyOptions & { withResponse: false }): Promise; - public deferReply(options?: InteractionDeferReplyOptions): Promise; + public deferReply( + options?: InteractionDeferReplyOptions, + ): Promise> | undefined>; public deleteReply(message?: MessageResolvable | '@original'): Promise; public editReply( options: string | MessagePayload | InteractionEditReplyOptions, ): Promise>>; public fetchReply(message?: Snowflake | '@original'): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; - public reply(options: InteractionReplyOptions & { withResponse: true }): Promise; + public reply( + options: InteractionReplyOptions & { withResponse: true }, + ): Promise>>; public reply(options: InteractionReplyOptions & { withResponse: false }): Promise; public reply( options: string | MessagePayload | InteractionReplyOptions, - ): Promise; + ): Promise> | undefined>; public showModal( modal: | JSONEncodable | ModalComponentData | APIModalInteractionResponseCallbackData, options: ShowModalOptions & { withResponse: true }, - ): Promise; + ): Promise>>; public showModal( modal: | JSONEncodable @@ -605,7 +609,7 @@ export abstract class CommandInteraction e | ModalComponentData | APIModalInteractionResponseCallbackData, options?: ShowModalOptions, - ): Promise; + ): Promise> | undefined>; public awaitModalSubmit( options: AwaitModalSubmitOptions, ): Promise>; @@ -1952,17 +1956,17 @@ export class InteractionCallback { public type: InteractionType; } -export class InteractionCallbackResponse { +export class InteractionCallbackResponse { private constructor(client: Client, data: RESTPostAPIInteractionCallbackWithResponseResult); public readonly client: Client; public interaction: InteractionCallback; - public resource: InteractionCallbackResource | null; + public resource: InteractionCallbackResource | null; } -export class InteractionCallbackResource { +export class InteractionCallbackResource { private constructor(client: Client, data: RESTAPIInteractionCallbackResourceObject); public activityInstance: RESTAPIInteractionCallbackActivityInstanceResource | null; - public message: Message | null; + public message: Message | null; public type: InteractionResponseType; } @@ -2265,37 +2269,45 @@ export class MessageComponentInteraction e public inRawGuild(): this is MessageComponentInteraction<'raw'>; public deferReply( options: InteractionDeferReplyOptions & { withResponse: true }, - ): Promise; + ): Promise>>; public deferReply(options?: InteractionDeferReplyOptions & { withResponse: false }): Promise; - public deferReply(options?: InteractionDeferReplyOptions): Promise; + public deferReply( + options?: InteractionDeferReplyOptions, + ): Promise> | undefined>; public deferUpdate( options: InteractionDeferUpdateOptions & { withResponse: true }, - ): Promise; + ): Promise>>; public deferUpdate(options?: InteractionDeferUpdateOptions & { withResponse: false }): Promise; - public deferUpdate(options?: InteractionDeferUpdateOptions): Promise; + public deferUpdate( + options?: InteractionDeferUpdateOptions, + ): Promise> | undefined>; public deleteReply(message?: MessageResolvable | '@original'): Promise; public editReply( options: string | MessagePayload | InteractionEditReplyOptions, ): Promise>>; public fetchReply(message?: Snowflake | '@original'): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; - public reply(options: InteractionReplyOptions & { withResponse: true }): Promise; + public reply( + options: InteractionReplyOptions & { withResponse: true }, + ): Promise>>; public reply(options: InteractionReplyOptions & { withResponse: false }): Promise; public reply( options: string | MessagePayload | InteractionReplyOptions, - ): Promise; - public update(options: InteractionUpdateOptions & { withResponse: true }): Promise; + ): Promise> | undefined>; + public update( + options: InteractionUpdateOptions & { withResponse: true }, + ): Promise>>; public update(options: InteractionUpdateOptions & { withResponse: false }): Promise; public update( options: string | MessagePayload | InteractionUpdateOptions, - ): Promise; + ): Promise> | undefined>; public showModal( modal: | JSONEncodable | ModalComponentData | APIModalInteractionResponseCallbackData, options: ShowModalOptions & { withResponse: true }, - ): Promise; + ): Promise>>; public showModal( modal: | JSONEncodable @@ -2309,7 +2321,7 @@ export class MessageComponentInteraction e | ModalComponentData | APIModalInteractionResponseCallbackData, options?: ShowModalOptions, - ): Promise; + ): Promise> | undefined>; public awaitModalSubmit( options: AwaitModalSubmitOptions, ): Promise>; @@ -2477,9 +2489,13 @@ export interface ModalMessageModalSubmitInteraction { message: Message>; channelId: Snowflake; - update(options: InteractionUpdateOptions & { withResponse: true }): Promise; + update( + options: InteractionUpdateOptions & { withResponse: true }, + ): Promise>>; update(options: InteractionUpdateOptions & { withResponse: false }): Promise; - update(options: string | MessagePayload | InteractionUpdateOptions): Promise; + update( + options: string | MessagePayload | InteractionUpdateOptions, + ): Promise> | undefined>; inGuild(): this is ModalMessageModalSubmitInteraction<'raw' | 'cached'>; inCachedGuild(): this is ModalMessageModalSubmitInteraction<'cached'>; inRawGuild(): this is ModalMessageModalSubmitInteraction<'raw'>; @@ -2496,27 +2512,33 @@ export class ModalSubmitInteraction extend public message: Message> | null; public replied: boolean; public readonly webhook: InteractionWebhook; - public reply(options: InteractionReplyOptions & { withResponse: true }): Promise; + public reply( + options: InteractionReplyOptions & { withResponse: true }, + ): Promise>>; public reply(options: InteractionReplyOptions & { withResponse: false }): Promise; public reply( options: string | MessagePayload | InteractionReplyOptions, - ): Promise; + ): Promise> | undefined>; public deleteReply(message?: MessageResolvable | '@original'): Promise; public editReply( options: string | MessagePayload | InteractionEditReplyOptions, ): Promise>>; public deferReply( options: InteractionDeferReplyOptions & { withResponse: true }, - ): Promise; + ): Promise>>; public deferReply(options?: InteractionDeferReplyOptions & { withResponse: false }): Promise; - public deferReply(options?: InteractionDeferReplyOptions): Promise; + public deferReply( + options?: InteractionDeferReplyOptions, + ): Promise> | undefined>; public fetchReply(message?: Snowflake | '@original'): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; public deferUpdate( options: InteractionDeferUpdateOptions & { withResponse: true }, - ): Promise; + ): Promise>>; public deferUpdate(options?: InteractionDeferUpdateOptions & { withResponse: false }): Promise; - public deferUpdate(options?: InteractionDeferUpdateOptions): Promise; + public deferUpdate( + options?: InteractionDeferUpdateOptions, + ): Promise> | undefined>; public inGuild(): this is ModalSubmitInteraction<'raw' | 'cached'>; public inCachedGuild(): this is ModalSubmitInteraction<'cached'>; public inRawGuild(): this is ModalSubmitInteraction<'raw'>; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 7b9aea274..4396e6a5f 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -450,7 +450,7 @@ client.on('messageCreate', async message => { expectAssignable>(message); const component = await message.awaitMessageComponent({ componentType: ComponentType.Button }); expectType>(component); - expectType(await component.reply({ withResponse: true })); + expectType>(await component.reply({ withResponse: true })); const buttonCollector = message.createMessageComponentCollector({ componentType: ComponentType.Button }); expectType>>(buttonCollector); @@ -1878,21 +1878,21 @@ client.on('interactionCreate', async interaction => { expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); - expectType>(interaction.reply({ content: 'a', withResponse: true })); - expectType>(interaction.deferReply({ withResponse: true })); + expectType>>(interaction.reply({ content: 'a', withResponse: true })); + expectType>>(interaction.deferReply({ withResponse: true })); expectType>(interaction.deferReply()); expectType>(interaction.reply({ content: 'a', withResponse: false })); expectType>(interaction.deferReply({ withResponse: false })); - expectType>( + expectType | undefined>>( interaction.reply({ content: 'a', withResponse: booleanValue }), ); - expectType>( + expectType | undefined>>( interaction.deferReply({ withResponse: booleanValue }), ); expectType>>(interaction.editReply({ content: 'a' })); expectType>>(interaction.fetchReply()); - expectType>(interaction.update({ content: 'a', withResponse: true })); - expectType>(interaction.deferUpdate({ withResponse: true })); + expectType>>(interaction.update({ content: 'a', withResponse: true })); + expectType>>(interaction.deferUpdate({ withResponse: true })); expectType>(interaction.deferUpdate()); expectType>>(interaction.followUp({ content: 'a' })); } else if (interaction.inRawGuild()) { @@ -1900,25 +1900,25 @@ client.on('interactionCreate', async interaction => { expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); - expectType>(interaction.reply({ content: 'a', withResponse: true })); - expectType>(interaction.deferReply({ withResponse: true })); + expectType>>(interaction.reply({ content: 'a', withResponse: true })); + expectType>>(interaction.deferReply({ withResponse: true })); expectType>(interaction.reply({ content: 'a', withResponse: false })); expectType>(interaction.deferReply({ withResponse: false })); expectType>(interaction.deferReply()); - expectType>( + expectType | undefined>>( interaction.reply({ content: 'a', withResponse: booleanValue }), ); - expectType>( + expectType | undefined>>( interaction.deferReply({ withResponse: booleanValue }), ); expectType>>(interaction.editReply({ content: 'a' })); expectType>>(interaction.fetchReply()); - expectType>(interaction.update({ content: 'a', withResponse: true })); + expectType>>(interaction.update({ content: 'a', withResponse: true })); expectType>(interaction.update({ content: 'a', withResponse: false })); - expectType>( + expectType | undefined>>( interaction.update({ content: 'a', withResponse: booleanValue }), ); - expectType>(interaction.deferUpdate({ withResponse: true })); + expectType>>(interaction.deferUpdate({ withResponse: true })); expectType>(interaction.deferUpdate()); expectType>>(interaction.followUp({ content: 'a' })); } else if (interaction.inGuild()) { @@ -1979,15 +1979,15 @@ client.on('interactionCreate', async interaction => { expectAssignable(interaction); expectAssignable(interaction.guild); expectAssignable>(interaction); - expectType>(interaction.reply({ content: 'a', withResponse: true })); - expectType>(interaction.deferReply({ withResponse: true })); + expectType>>(interaction.reply({ content: 'a', withResponse: true })); + expectType>>(interaction.deferReply({ withResponse: true })); expectType>(interaction.deferReply()); expectType>(interaction.reply({ content: 'a', withResponse: false })); expectType>(interaction.deferReply({ withResponse: false })); - expectType>( + expectType | undefined>>( interaction.reply({ content: 'a', withResponse: booleanValue }), ); - expectType>( + expectType | undefined>>( interaction.deferReply({ withResponse: booleanValue }), ); expectType>>(interaction.editReply({ content: 'a' })); @@ -1996,15 +1996,15 @@ client.on('interactionCreate', async interaction => { } else if (interaction.inRawGuild()) { expectAssignable(interaction); expectType(interaction.guild); - expectType>(interaction.reply({ content: 'a', withResponse: true })); - expectType>(interaction.deferReply({ withResponse: true })); + expectType>>(interaction.reply({ content: 'a', withResponse: true })); + expectType>>(interaction.deferReply({ withResponse: true })); expectType>(interaction.deferReply()); expectType>(interaction.reply({ content: 'a', withResponse: false })); expectType>(interaction.deferReply({ withResponse: false })); - expectType>( + expectType | undefined>>( interaction.reply({ content: 'a', withResponse: booleanValue }), ); - expectType>( + expectType | undefined>>( interaction.deferReply({ withResponse: booleanValue }), ); expectType>>(interaction.editReply({ content: 'a' })); @@ -2077,13 +2077,13 @@ client.on('interactionCreate', async interaction => { expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); - expectType>(interaction.reply({ withResponse: true })); + expectType>>(interaction.reply({ withResponse: true })); } else if (interaction.inRawGuild()) { expectAssignable(interaction); expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); - expectType>(interaction.reply({ withResponse: true })); + expectType>>(interaction.reply({ withResponse: true })); } else if (interaction.inGuild()) { expectAssignable(interaction); expectType(interaction.component); @@ -2105,13 +2105,13 @@ client.on('interactionCreate', async interaction => { expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); - expectType>(interaction.reply({ withResponse: true })); + expectType>>(interaction.reply({ withResponse: true })); } else if (interaction.inRawGuild()) { expectAssignable(interaction); expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); - expectType>(interaction.reply({ withResponse: true })); + expectType>>(interaction.reply({ withResponse: true })); } else if (interaction.inGuild()) { expectAssignable(interaction); expectType(interaction.component); @@ -2128,7 +2128,7 @@ client.on('interactionCreate', async interaction => { if (interaction.inRawGuild()) { expectNotAssignable>(interaction); expectAssignable(interaction); - expectType>(interaction.reply({ withResponse: true })); + expectType>>(interaction.reply({ withResponse: true })); expectType(interaction.options.getMember('test')); expectType(interaction.options.getChannel('test', true)); @@ -2136,7 +2136,7 @@ client.on('interactionCreate', async interaction => { } else if (interaction.inCachedGuild()) { expectType(interaction.options.getMember('test')); expectAssignable(interaction); - expectType>(interaction.reply({ withResponse: true })); + expectType>>(interaction.reply({ withResponse: true })); expectType(interaction.options.getChannel('test', true)); expectType(interaction.options.getRole('test', true)); @@ -2215,23 +2215,23 @@ client.on('interactionCreate', async interaction => { if (interaction.inCachedGuild()) { expectAssignable(interaction); expectType(interaction.guild); - expectType>(interaction.reply({ content: 'a', withResponse: true })); - expectType>(interaction.deferReply({ withResponse: true })); + expectType>>(interaction.reply({ content: 'a', withResponse: true })); + expectType>>(interaction.deferReply({ withResponse: true })); expectType>(interaction.deferReply()); expectType>>(interaction.editReply({ content: 'a' })); expectType>>(interaction.fetchReply()); - expectType>(interaction.deferUpdate({ withResponse: true })); + expectType>>(interaction.deferUpdate({ withResponse: true })); expectType>(interaction.deferUpdate()); expectType>>(interaction.followUp({ content: 'a' })); } else if (interaction.inRawGuild()) { expectAssignable(interaction); expectType(interaction.guild); - expectType>(interaction.reply({ content: 'a', withResponse: true })); - expectType>(interaction.deferReply({ withResponse: true })); + expectType>>(interaction.reply({ content: 'a', withResponse: true })); + expectType>>(interaction.deferReply({ withResponse: true })); expectType>(interaction.deferReply()); expectType>>(interaction.editReply({ content: 'a' })); expectType>>(interaction.fetchReply()); - expectType>(interaction.deferUpdate({ withResponse: true })); + expectType>>(interaction.deferUpdate({ withResponse: true })); expectType>(interaction.deferUpdate()); expectType>>(interaction.followUp({ content: 'a' })); } else if (interaction.inGuild()) {