From 10b9880894b622ee14e6d894798db73f93cc998d Mon Sep 17 00:00:00 2001 From: Qjuh <76154676+Qjuh@users.noreply.github.com> Date: Tue, 28 Nov 2023 17:23:57 +0100 Subject: [PATCH] types: omit getAttachment and add tests --- packages/discord.js/typings/index.d.ts | 1 + packages/discord.js/typings/index.test-d.ts | 49 +++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 978c4a39177f7..53e9610725355 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -3241,6 +3241,7 @@ export class UserContextMenuCommandInteraction< | 'getMentionable' | 'getRole' | 'getNumber' + | 'getAttachment' | 'getInteger' | 'getString' | 'getChannel' diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index d81c9d524ab6d..9d40a731f67e5 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -1508,6 +1508,26 @@ declare const applicationCommandSubGroup: ApplicationCommandSubGroup; applicationCommandSubGroup.options = [] as const; } +declare const userContextMenuCommandInteraction: UserContextMenuCommandInteraction; +{ + expectType(userContextMenuCommandInteraction.options.getUser('useroption')); + expectType(userContextMenuCommandInteraction.options.getUser('useroption', true)); + expectType( + userContextMenuCommandInteraction.options.getMember('useroption'), + ); + if (userContextMenuCommandInteraction.inCachedGuild()) { + expectType(userContextMenuCommandInteraction.options.getMember('useroption')); + } +} + +declare const messageContextMenuCommandInteraction: MessageContextMenuCommandInteraction; +{ + expectType(messageContextMenuCommandInteraction.options.getMessage('message', true)); + expectType( + userContextMenuCommandInteraction.options.getMember('useroption'), + ); +} + declare const autoModerationRuleManager: AutoModerationRuleManager; { expectType>(autoModerationRuleManager.fetch('1234567890')); @@ -1803,6 +1823,8 @@ client.on('interactionCreate', async interaction => { interaction.commandType === ApplicationCommandType.Message) ) { expectType(interaction); + // @ts-expect-error No attachment options on contextmenu commands + interaction.options.getAttachment('name'); if (interaction.inCachedGuild()) { expectAssignable(interaction); expectAssignable(interaction.guild); @@ -1836,12 +1858,36 @@ client.on('interactionCreate', async interaction => { interaction.commandType === ApplicationCommandType.Message ) { expectType(interaction.targetMessage); + expectType(interaction.options.getMessage('_MESSAGE')); if (interaction.inCachedGuild()) { expectType>(interaction.targetMessage); + expectType | null>(interaction.options.getMessage('_MESSAGE')); } else if (interaction.inRawGuild()) { expectType>(interaction.targetMessage); + expectType | null>(interaction.options.getMessage('_MESSAGE')); } else if (interaction.inGuild()) { expectType(interaction.targetMessage); + expectType(interaction.options.getMessage('_MESSAGE')); + } + } + + if ( + interaction.type === InteractionType.ApplicationCommand && + interaction.commandType === ApplicationCommandType.User + ) { + expectType(interaction.targetUser); + expectType(interaction.targetMember); + expectType(interaction.options.getUser('user')); + expectType(interaction.options.getMember('user')); + if (interaction.inCachedGuild()) { + expectType(interaction.targetMember); + expectType(interaction.options.getMember('user')); + } else if (interaction.inRawGuild()) { + expectType(interaction.targetMember); + expectType(interaction.options.getMember('user')); + } else if (interaction.inGuild()) { + expectType(interaction.targetMember); + expectType(interaction.options.getMember('user')); } } @@ -1975,6 +2021,9 @@ client.on('interactionCreate', async interaction => { expectType(interaction.options.getSubcommandGroup()); expectType(interaction.options.getSubcommandGroup(booleanValue)); expectType(interaction.options.getSubcommandGroup(false)); + + // @ts-expect-error + interaction.options.getMessage('name'); } if (interaction.isRepliable()) {