Skip to content

Commit

Permalink
types: omit getAttachment and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Qjuh committed Nov 28, 2023
1 parent 4d0077a commit 10b9880
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3241,6 +3241,7 @@ export class UserContextMenuCommandInteraction<
| 'getMentionable'
| 'getRole'
| 'getNumber'
| 'getAttachment'
| 'getInteger'
| 'getString'
| 'getChannel'
Expand Down
49 changes: 49 additions & 0 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,26 @@ declare const applicationCommandSubGroup: ApplicationCommandSubGroup;
applicationCommandSubGroup.options = [] as const;
}

declare const userContextMenuCommandInteraction: UserContextMenuCommandInteraction;
{
expectType<User | null>(userContextMenuCommandInteraction.options.getUser('useroption'));
expectType<User>(userContextMenuCommandInteraction.options.getUser('useroption', true));
expectType<GuildMember | APIInteractionDataResolvedGuildMember | null>(
userContextMenuCommandInteraction.options.getMember('useroption'),
);
if (userContextMenuCommandInteraction.inCachedGuild()) {
expectType<GuildMember | null>(userContextMenuCommandInteraction.options.getMember('useroption'));
}
}

declare const messageContextMenuCommandInteraction: MessageContextMenuCommandInteraction;
{
expectType<Message>(messageContextMenuCommandInteraction.options.getMessage('message', true));
expectType<GuildMember | APIInteractionDataResolvedGuildMember | null>(
userContextMenuCommandInteraction.options.getMember('useroption'),
);
}

declare const autoModerationRuleManager: AutoModerationRuleManager;
{
expectType<Promise<AutoModerationRule>>(autoModerationRuleManager.fetch('1234567890'));
Expand Down Expand Up @@ -1803,6 +1823,8 @@ client.on('interactionCreate', async interaction => {
interaction.commandType === ApplicationCommandType.Message)
) {
expectType<MessageContextMenuCommandInteraction | UserContextMenuCommandInteraction>(interaction);
// @ts-expect-error No attachment options on contextmenu commands
interaction.options.getAttachment('name');
if (interaction.inCachedGuild()) {
expectAssignable<ContextMenuCommandInteraction>(interaction);
expectAssignable<Guild>(interaction.guild);
Expand Down Expand Up @@ -1836,12 +1858,36 @@ client.on('interactionCreate', async interaction => {
interaction.commandType === ApplicationCommandType.Message
) {
expectType<Message>(interaction.targetMessage);
expectType<Message | null>(interaction.options.getMessage('_MESSAGE'));
if (interaction.inCachedGuild()) {
expectType<Message<true>>(interaction.targetMessage);
expectType<Message<true> | null>(interaction.options.getMessage('_MESSAGE'));
} else if (interaction.inRawGuild()) {
expectType<Message<false>>(interaction.targetMessage);
expectType<Message<false> | null>(interaction.options.getMessage('_MESSAGE'));
} else if (interaction.inGuild()) {
expectType<Message>(interaction.targetMessage);
expectType<Message | null>(interaction.options.getMessage('_MESSAGE'));
}
}

if (
interaction.type === InteractionType.ApplicationCommand &&
interaction.commandType === ApplicationCommandType.User
) {
expectType<User>(interaction.targetUser);
expectType<GuildMember | APIInteractionGuildMember | null>(interaction.targetMember);
expectType<User | null>(interaction.options.getUser('user'));
expectType<GuildMember | APIInteractionDataResolvedGuildMember | null>(interaction.options.getMember('user'));
if (interaction.inCachedGuild()) {
expectType<GuildMember | null>(interaction.targetMember);
expectType<GuildMember | null>(interaction.options.getMember('user'));
} else if (interaction.inRawGuild()) {
expectType<APIInteractionGuildMember | null>(interaction.targetMember);
expectType<APIInteractionDataResolvedGuildMember | null>(interaction.options.getMember('user'));
} else if (interaction.inGuild()) {
expectType<GuildMember | APIInteractionGuildMember | null>(interaction.targetMember);
expectType<GuildMember | APIInteractionDataResolvedGuildMember | null>(interaction.options.getMember('user'));
}
}

Expand Down Expand Up @@ -1975,6 +2021,9 @@ client.on('interactionCreate', async interaction => {
expectType<string | null>(interaction.options.getSubcommandGroup());
expectType<string | null>(interaction.options.getSubcommandGroup(booleanValue));
expectType<string | null>(interaction.options.getSubcommandGroup(false));

// @ts-expect-error
interaction.options.getMessage('name');
}

if (interaction.isRepliable()) {
Expand Down

0 comments on commit 10b9880

Please sign in to comment.