From c33ab7d82deb031a03f45219e29cb2cf56eb38bd Mon Sep 17 00:00:00 2001 From: Maksi <96802571+MaksiRose@users.noreply.github.com> Date: Sun, 28 Aug 2022 12:13:39 +0200 Subject: [PATCH 1/4] feat: add typeguard to BaseInteraction#isRepliable --- packages/discord.js/typings/index.d.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 351a33220bcd..0e936e5d4313 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1503,6 +1503,11 @@ export type Interaction = | AutocompleteInteraction | ModalSubmitInteraction; +export type RepliableInteraction = + | CommandInteraction + | MessageComponentInteraction + | ModalSubmitInteraction; + export class BaseInteraction extends Base { // This a technique used to brand different cached types. Or else we'll get `never` errors on typeguard checks. private readonly _cacheType: Cached; @@ -1543,7 +1548,7 @@ export class BaseInteraction extends Base public isModalSubmit(): this is ModalSubmitInteraction; public isUserContextMenuCommand(): this is UserContextMenuCommandInteraction; public isSelectMenu(): this is SelectMenuInteraction; - public isRepliable(): this is this & InteractionResponseFields; + public isRepliable(): this is RepliableInteraction; } export class InteractionCollector extends Collector< From 210e8408b95ccf1f098134756f558858bc37cd98 Mon Sep 17 00:00:00 2001 From: Maksi <96802571+MaksiRose@users.noreply.github.com> Date: Sun, 28 Aug 2022 13:08:03 +0200 Subject: [PATCH 2/4] fix: redefine RepliableInteraaction ...to exclude impossible interactions rather than specify possible ones Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- packages/discord.js/typings/index.d.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 0e936e5d4313..b61cddc1ce29 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1503,11 +1503,7 @@ export type Interaction = | AutocompleteInteraction | ModalSubmitInteraction; -export type RepliableInteraction = - | CommandInteraction - | MessageComponentInteraction - | ModalSubmitInteraction; - +export type RepliableInteraction = Exclude; export class BaseInteraction extends Base { // This a technique used to brand different cached types. Or else we'll get `never` errors on typeguard checks. private readonly _cacheType: Cached; From 9e47661e321a71566acd1224481d2d0e1a8e1ee4 Mon Sep 17 00:00:00 2001 From: Maksi <96802571+MaksiRose@users.noreply.github.com> Date: Sun, 28 Aug 2022 17:11:51 +0200 Subject: [PATCH 3/4] fix: remove InteractionResponseFields --- packages/discord.js/typings/index.d.ts | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index b61cddc1ce29..baea42ee118e 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -398,28 +398,6 @@ export type GuildCacheMessage = CacheTypeReducer< Message | APIMessage >; -export interface InteractionResponseFields { - deferred: boolean; - ephemeral: boolean | null; - replied: boolean; - webhook: InteractionWebhook; - reply(options: InteractionReplyOptions & { fetchReply: true }): Promise; - reply(options: string | MessagePayload | InteractionReplyOptions): Promise; - deleteReply(): Promise; - editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise; - deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise; - deferReply(options?: InteractionDeferReplyOptions): Promise; - fetchReply(): Promise; - followUp(options: string | MessagePayload | InteractionReplyOptions): Promise; - showModal( - modal: - | JSONEncodable - | ModalComponentData - | APIModalInteractionResponseCallbackData, - ): Promise; - awaitModalSubmit(options: AwaitModalSubmitOptions): Promise>; -} - export type BooleanCache = T extends 'cached' ? true : false; export abstract class CommandInteraction extends BaseInteraction { From f2f3fbc94525c610e1e2f4bb1c0d1e2d96ab3100 Mon Sep 17 00:00:00 2001 From: Maksi <96802571+MaksiRose@users.noreply.github.com> Date: Tue, 6 Sep 2022 10:40:59 +0200 Subject: [PATCH 4/4] fix: replace InteractionResponseFields with RepliableInteraction in index test --- packages/discord.js/typings/index.test-d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 79c7bf06fa56..3a027d871a09 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -100,7 +100,7 @@ import { ActionRowBuilder, ButtonComponent, SelectMenuComponent, - InteractionResponseFields, + RepliableInteraction, ThreadChannelType, Events, WebSocketShardEvents, @@ -1519,7 +1519,7 @@ client.on('interactionCreate', async interaction => { } if (interaction.isRepliable()) { - expectAssignable(interaction); + expectAssignable(interaction); interaction.reply('test'); } @@ -1529,7 +1529,7 @@ client.on('interactionCreate', async interaction => { interaction.isRepliable() ) { expectAssignable(interaction); - expectAssignable(interaction); + expectAssignable(interaction); } });