mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
types: Strengthen autocomplete option types (#6950)
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
15
typings/index.d.ts
vendored
15
typings/index.d.ts
vendored
@@ -3313,7 +3313,6 @@ export interface BaseApplicationCommandOptionsData {
|
||||
name: string;
|
||||
description: string;
|
||||
required?: boolean;
|
||||
autocomplete?: boolean;
|
||||
}
|
||||
|
||||
export interface UserApplicationCommandData extends BaseApplicationCommandData {
|
||||
@@ -3346,14 +3345,27 @@ export interface ApplicationCommandChannelOption extends BaseApplicationCommandO
|
||||
channelTypes?: (keyof typeof ChannelTypes)[];
|
||||
}
|
||||
|
||||
export interface ApplicationCommandAutocompleteOption extends BaseApplicationCommandOptionsData {
|
||||
type:
|
||||
| 'STRING'
|
||||
| 'NUMBER'
|
||||
| 'INTEGER'
|
||||
| ApplicationCommandOptionTypes.STRING
|
||||
| ApplicationCommandOptionTypes.NUMBER
|
||||
| ApplicationCommandOptionTypes.INTEGER;
|
||||
autocomplete: true;
|
||||
}
|
||||
|
||||
export interface ApplicationCommandChoicesData extends BaseApplicationCommandOptionsData {
|
||||
type: CommandOptionChoiceResolvableType;
|
||||
choices?: ApplicationCommandOptionChoice[];
|
||||
autocomplete?: false;
|
||||
}
|
||||
|
||||
export interface ApplicationCommandChoicesOption extends BaseApplicationCommandOptionsData {
|
||||
type: Exclude<CommandOptionChoiceResolvableType, ApplicationCommandOptionTypes>;
|
||||
choices?: ApplicationCommandOptionChoice[];
|
||||
autocomplete?: false;
|
||||
}
|
||||
|
||||
export interface ApplicationCommandNumericOptionData extends ApplicationCommandChoicesData {
|
||||
@@ -3403,6 +3415,7 @@ export type ApplicationCommandOptionData =
|
||||
| ApplicationCommandNonOptionsData
|
||||
| ApplicationCommandChannelOptionData
|
||||
| ApplicationCommandChoicesData
|
||||
| ApplicationCommandAutocompleteOption
|
||||
| ApplicationCommandNumericOptionData
|
||||
| ApplicationCommandSubCommandData;
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ import {
|
||||
CommandInteraction,
|
||||
CommandInteractionOption,
|
||||
CommandInteractionOptionResolver,
|
||||
CommandOptionChoiceResolvableType,
|
||||
CommandOptionNonChoiceResolvableType,
|
||||
Constants,
|
||||
ContextMenuInteraction,
|
||||
@@ -447,6 +446,66 @@ client.on('ready', async () => {
|
||||
// This is to check that stuff is the right type
|
||||
declare const assertIsPromiseMember: (m: Promise<GuildMember>) => void;
|
||||
|
||||
const baseCommandOptionData = {
|
||||
name: 'test',
|
||||
description: 'test',
|
||||
};
|
||||
|
||||
assertType<ApplicationCommandOptionData>({
|
||||
...baseCommandOptionData,
|
||||
type: 'STRING',
|
||||
// @ts-expect-error
|
||||
autocomplete: true,
|
||||
choices: [],
|
||||
});
|
||||
|
||||
assertType<ApplicationCommandOptionData>({
|
||||
...baseCommandOptionData,
|
||||
type: 'STRING',
|
||||
autocomplete: false,
|
||||
choices: [],
|
||||
});
|
||||
|
||||
assertType<ApplicationCommandOptionData>({
|
||||
...baseCommandOptionData,
|
||||
type: 'STRING',
|
||||
choices: [],
|
||||
});
|
||||
|
||||
assertType<ApplicationCommandOptionData>({
|
||||
...baseCommandOptionData,
|
||||
type: 'NUMBER',
|
||||
// @ts-expect-error
|
||||
autocomplete: true,
|
||||
choices: [],
|
||||
});
|
||||
|
||||
assertType<ApplicationCommandOptionData>({
|
||||
...baseCommandOptionData,
|
||||
type: 'INTEGER',
|
||||
// @ts-expect-error
|
||||
autocomplete: true,
|
||||
choices: [],
|
||||
});
|
||||
|
||||
assertType<ApplicationCommandOptionData>({
|
||||
...baseCommandOptionData,
|
||||
type: 'NUMBER',
|
||||
autocomplete: true,
|
||||
});
|
||||
|
||||
assertType<ApplicationCommandOptionData>({
|
||||
...baseCommandOptionData,
|
||||
type: 'STRING',
|
||||
autocomplete: true,
|
||||
});
|
||||
|
||||
assertType<ApplicationCommandOptionData>({
|
||||
...baseCommandOptionData,
|
||||
type: 'INTEGER',
|
||||
autocomplete: true,
|
||||
});
|
||||
|
||||
client.on('guildCreate', async g => {
|
||||
const channel = g.channels.cache.random();
|
||||
if (!channel) return;
|
||||
@@ -820,12 +879,6 @@ declare const applicationNonChoiceOptionData: ApplicationCommandOptionData & {
|
||||
applicationNonChoiceOptionData.choices;
|
||||
}
|
||||
|
||||
declare const applicationChoiceOptionData: ApplicationCommandOptionData & { type: CommandOptionChoiceResolvableType };
|
||||
{
|
||||
// Choices should be available.
|
||||
applicationChoiceOptionData.choices;
|
||||
}
|
||||
|
||||
declare const applicationSubGroupCommandData: ApplicationCommandSubGroupData;
|
||||
{
|
||||
assertType<'SUB_COMMAND_GROUP' | ApplicationCommandOptionTypes.SUB_COMMAND_GROUP>(
|
||||
|
||||
Reference in New Issue
Block a user