Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: omit unnecessary methods from <ContextMenuCommandInteraction>.options #10003

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@ export abstract class CommandInteraction<Cached extends CacheType = CacheType> e
| 'getFocused'
| 'getMentionable'
| 'getRole'
| 'getUser'
| 'getMember'
| 'getAttachment'
| 'getNumber'
| 'getInteger'
Expand Down Expand Up @@ -1269,19 +1271,6 @@ export class CommandInteractionOptionResolver<Cached extends CacheType = CacheTy

export class ContextMenuCommandInteraction<Cached extends CacheType = CacheType> extends CommandInteraction<Cached> {
public commandType: ApplicationCommandType.Message | ApplicationCommandType.User;
public options: Omit<
CommandInteractionOptionResolver<Cached>,
| 'getFocused'
| 'getMentionable'
| 'getRole'
| 'getNumber'
| 'getInteger'
| 'getString'
| 'getChannel'
| 'getBoolean'
| 'getSubcommandGroup'
| 'getSubcommand'
>;
public targetId: Snowflake;
public inGuild(): this is ContextMenuCommandInteraction<'raw' | 'cached'>;
public inCachedGuild(): this is ContextMenuCommandInteraction<'cached'>;
Expand Down Expand Up @@ -2222,6 +2211,21 @@ export class MessageContextMenuCommandInteraction<
Cached extends CacheType = CacheType,
> extends ContextMenuCommandInteraction<Cached> {
public commandType: ApplicationCommandType.Message;
public options: Omit<
CommandInteractionOptionResolver<Cached>,
| 'getFocused'
| 'getMentionable'
| 'getRole'
| 'getUser'
| 'getNumber'
| 'getAttachment'
| 'getInteger'
| 'getString'
| 'getChannel'
| 'getBoolean'
| 'getSubcommandGroup'
| 'getSubcommand'
>;
public get targetMessage(): NonNullable<CommandInteractionOption<Cached>['message']>;
public inGuild(): this is MessageContextMenuCommandInteraction<'raw' | 'cached'>;
public inCachedGuild(): this is MessageContextMenuCommandInteraction<'cached'>;
Expand Down Expand Up @@ -3233,6 +3237,21 @@ export class UserContextMenuCommandInteraction<
Cached extends CacheType = CacheType,
> extends ContextMenuCommandInteraction<Cached> {
public commandType: ApplicationCommandType.User;
public options: Omit<
CommandInteractionOptionResolver<Cached>,
| 'getMessage'
| 'getFocused'
| 'getMentionable'
| 'getRole'
| 'getNumber'
| 'getAttachment'
| 'getInteger'
| 'getString'
| 'getChannel'
| 'getBoolean'
| 'getSubcommandGroup'
| 'getSubcommand'
>;
public get targetUser(): User;
public get targetMember(): CacheTypeReducer<Cached, GuildMember, APIInteractionGuildMember> | null;
public inGuild(): this is UserContextMenuCommandInteraction<'raw' | 'cached'>;
Expand Down
29 changes: 29 additions & 0 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,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 +1838,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 +2001,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