From 55c3ee20ae700e78d18a3c4c04b6a7426cffc060 Mon Sep 17 00:00:00 2001 From: Maksi <96802571+MaksiRose@users.noreply.github.com> Date: Tue, 6 Sep 2022 19:56:21 +0200 Subject: [PATCH] feat: add typeguard to BaseInteraction#isRepliable (#8565) * feat: add typeguard to BaseInteraction#isRepliable * fix: redefine RepliableInteraaction ...to exclude impossible interactions rather than specify possible ones Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * fix: remove InteractionResponseFields * fix: replace InteractionResponseFields with RepliableInteraction in index test Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/discord.js/typings/index.d.ts | 25 ++------------------- packages/discord.js/typings/index.test-d.ts | 6 ++--- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index c450df38fe44..ea03e53d3a71 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 { @@ -1504,6 +1482,7 @@ export type Interaction = | AutocompleteInteraction | 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; @@ -1544,7 +1523,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< 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); } });