From 053da5bc91d5cfa8d842b13b0b05083d2f7f086d Mon Sep 17 00:00:00 2001 From: Almeida Date: Thu, 15 Sep 2022 19:18:48 +0100 Subject: [PATCH] types(interactions): pass `Cached` type to return type of methods (#8619) --- packages/discord.js/typings/index.d.ts | 24 ++++--- packages/discord.js/typings/index.test-d.ts | 74 +++++++++++++++++++-- 2 files changed, 85 insertions(+), 13 deletions(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 6153c98734df..851211d2b980 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -435,9 +435,11 @@ export abstract class CommandInteraction e ): Promise>>; public deferReply(options?: InteractionDeferReplyOptions): Promise>>; public deleteReply(): Promise; - public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise; - public fetchReply(): Promise; - public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise; + public editReply( + options: string | MessagePayload | WebhookEditMessageOptions, + ): Promise>>; + public fetchReply(): Promise>>; + public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise>>; public reply( options: string | MessagePayload | InteractionReplyOptions, @@ -1806,14 +1808,16 @@ export class MessageComponentInteraction e ): Promise>>; public deferUpdate(options?: InteractionDeferUpdateOptions): Promise>>; public deleteReply(): Promise; - public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise; - public fetchReply(): Promise; - public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise; + public editReply( + options: string | MessagePayload | WebhookEditMessageOptions, + ): Promise>>; + public fetchReply(): Promise>>; + public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise>>; public reply( options: string | MessagePayload | InteractionReplyOptions, ): Promise>>; - public update(options: InteractionUpdateOptions & { fetchReply: true }): Promise; + public update(options: InteractionUpdateOptions & { fetchReply: true }): Promise>>; public update( options: string | MessagePayload | InteractionUpdateOptions, ): Promise>>; @@ -1989,7 +1993,7 @@ export class ModalSubmitInteraction extend public message: Message> | null; public replied: boolean; public readonly webhook: InteractionWebhook; - public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise; + public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise>>; public reply( options: string | MessagePayload | InteractionReplyOptions, ): Promise>>; @@ -2003,7 +2007,9 @@ export class ModalSubmitInteraction extend public deferReply(options?: InteractionDeferReplyOptions): Promise>>; public fetchReply(): Promise>>; public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>>; - public deferUpdate(options: InteractionDeferUpdateOptions & { fetchReply: true }): Promise; + public deferUpdate( + options: InteractionDeferUpdateOptions & { fetchReply: true }, + ): Promise>>; public deferUpdate(options?: InteractionDeferUpdateOptions): Promise>>; public inGuild(): this is ModalSubmitInteraction<'raw' | 'cached'>; public inCachedGuild(): this is ModalSubmitInteraction<'cached'>; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 2b6a4a41e575..3ffaf2e5f9bb 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -136,6 +136,7 @@ import { InteractionWebhook, GuildAuditLogsActionType, GuildAuditLogsTargetType, + ModalSubmitInteraction, } from '.'; import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd'; import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders'; @@ -1488,19 +1489,37 @@ client.on('interactionCreate', async interaction => { expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); - expectAssignable>(interaction.reply({ fetchReply: true })); + expectType>>(interaction.reply({ content: 'a', fetchReply: true })); + expectType>>(interaction.deferReply({ fetchReply: true })); + expectType>>(interaction.editReply({ content: 'a' })); + expectType>>(interaction.fetchReply()); + expectType>>(interaction.update({ content: 'a', fetchReply: true })); + expectType>>(interaction.deferUpdate({ fetchReply: true })); + expectType>>(interaction.followUp({ content: 'a' })); } else if (interaction.inRawGuild()) { expectAssignable(interaction); expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); - expectType>>(interaction.reply({ fetchReply: true })); + expectType>>(interaction.reply({ content: 'a', fetchReply: true })); + expectType>>(interaction.deferReply({ fetchReply: true })); + expectType>>(interaction.editReply({ content: 'a' })); + expectType>>(interaction.fetchReply()); + expectType>>(interaction.update({ content: 'a', fetchReply: true })); + expectType>>(interaction.deferUpdate({ fetchReply: true })); + expectType>>(interaction.followUp({ content: 'a' })); } else if (interaction.inGuild()) { expectAssignable(interaction); expectType(interaction.component); expectType(interaction.message); expectType(interaction.guild); - expectType>(interaction.reply({ fetchReply: true })); + expectType>(interaction.reply({ content: 'a', fetchReply: true })); + expectType>(interaction.deferReply({ fetchReply: true })); + expectType>(interaction.editReply({ content: 'a' })); + expectType>(interaction.fetchReply()); + expectType>(interaction.update({ content: 'a', fetchReply: true })); + expectType>(interaction.deferUpdate({ fetchReply: true })); + expectType>(interaction.followUp({ content: 'a' })); } } @@ -1531,12 +1550,27 @@ client.on('interactionCreate', async interaction => { expectAssignable(interaction); expectAssignable(interaction.guild); expectAssignable>(interaction); + expectType>>(interaction.reply({ content: 'a', fetchReply: true })); + expectType>>(interaction.deferReply({ fetchReply: true })); + expectType>>(interaction.editReply({ content: 'a' })); + expectType>>(interaction.fetchReply()); + expectType>>(interaction.followUp({ content: 'a' })); } else if (interaction.inRawGuild()) { expectAssignable(interaction); expectType(interaction.guild); + expectType>>(interaction.reply({ content: 'a', fetchReply: true })); + expectType>>(interaction.deferReply({ fetchReply: true })); + expectType>>(interaction.editReply({ content: 'a' })); + expectType>>(interaction.fetchReply()); + expectType>>(interaction.followUp({ content: 'a' })); } else if (interaction.inGuild()) { expectAssignable(interaction); expectType(interaction.guild); + expectType>(interaction.reply({ content: 'a', fetchReply: true })); + expectType>(interaction.deferReply({ fetchReply: true })); + expectType>(interaction.editReply({ content: 'a' })); + expectType>(interaction.fetchReply()); + expectType>(interaction.followUp({ content: 'a' })); } } @@ -1563,7 +1597,7 @@ client.on('interactionCreate', async interaction => { expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); - expectAssignable>(interaction.reply({ fetchReply: true })); + expectType>>(interaction.reply({ fetchReply: true })); } else if (interaction.inRawGuild()) { expectAssignable(interaction); expectType(interaction.component); @@ -1678,6 +1712,38 @@ client.on('interactionCreate', async interaction => { expectAssignable(interaction); expectAssignable(interaction); } + + if (interaction.type === InteractionType.ModalSubmit && interaction.isRepliable()) { + expectType(interaction); + if (interaction.inCachedGuild()) { + expectAssignable(interaction); + expectType(interaction.guild); + expectType>>(interaction.reply({ content: 'a', fetchReply: true })); + expectType>>(interaction.deferReply({ fetchReply: true })); + expectType>>(interaction.editReply({ content: 'a' })); + expectType>>(interaction.fetchReply()); + expectType>>(interaction.deferUpdate({ fetchReply: true })); + expectType>>(interaction.followUp({ content: 'a' })); + } else if (interaction.inRawGuild()) { + expectAssignable(interaction); + expectType(interaction.guild); + expectType>>(interaction.reply({ content: 'a', fetchReply: true })); + expectType>>(interaction.deferReply({ fetchReply: true })); + expectType>>(interaction.editReply({ content: 'a' })); + expectType>>(interaction.fetchReply()); + expectType>>(interaction.deferUpdate({ fetchReply: true })); + expectType>>(interaction.followUp({ content: 'a' })); + } else if (interaction.inGuild()) { + expectAssignable(interaction); + expectType(interaction.guild); + expectType>(interaction.reply({ content: 'a', fetchReply: true })); + expectType>(interaction.deferReply({ fetchReply: true })); + expectType>(interaction.editReply({ content: 'a' })); + expectType>(interaction.fetchReply()); + expectType>(interaction.deferUpdate({ fetchReply: true })); + expectType>(interaction.followUp({ content: 'a' })); + } + } }); declare const shard: Shard;