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

* types: omit getUser/Member/Message from ContextMenu interaction

* types: omit getAttachment and add tests

* fix: remove duplicate tests
This commit is contained in:
Qjuh 2023-12-01 21:13:20 +01:00 committed by GitHub
parent a44ada661f
commit 17a6f5d3c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 13 deletions

View file

@ -542,6 +542,8 @@ export abstract class CommandInteraction<Cached extends CacheType = CacheType> e
| 'getFocused'
| 'getMentionable'
| 'getRole'
| 'getUser'
| 'getMember'
| 'getAttachment'
| 'getNumber'
| 'getInteger'
@ -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'>;
@ -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'>;
@ -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'>;

View file

@ -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);
@ -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'));
}
}
@ -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()) {