mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +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;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
autocomplete?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserApplicationCommandData extends BaseApplicationCommandData {
|
export interface UserApplicationCommandData extends BaseApplicationCommandData {
|
||||||
@@ -3346,14 +3345,27 @@ export interface ApplicationCommandChannelOption extends BaseApplicationCommandO
|
|||||||
channelTypes?: (keyof typeof ChannelTypes)[];
|
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 {
|
export interface ApplicationCommandChoicesData extends BaseApplicationCommandOptionsData {
|
||||||
type: CommandOptionChoiceResolvableType;
|
type: CommandOptionChoiceResolvableType;
|
||||||
choices?: ApplicationCommandOptionChoice[];
|
choices?: ApplicationCommandOptionChoice[];
|
||||||
|
autocomplete?: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandChoicesOption extends BaseApplicationCommandOptionsData {
|
export interface ApplicationCommandChoicesOption extends BaseApplicationCommandOptionsData {
|
||||||
type: Exclude<CommandOptionChoiceResolvableType, ApplicationCommandOptionTypes>;
|
type: Exclude<CommandOptionChoiceResolvableType, ApplicationCommandOptionTypes>;
|
||||||
choices?: ApplicationCommandOptionChoice[];
|
choices?: ApplicationCommandOptionChoice[];
|
||||||
|
autocomplete?: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationCommandNumericOptionData extends ApplicationCommandChoicesData {
|
export interface ApplicationCommandNumericOptionData extends ApplicationCommandChoicesData {
|
||||||
@@ -3403,6 +3415,7 @@ export type ApplicationCommandOptionData =
|
|||||||
| ApplicationCommandNonOptionsData
|
| ApplicationCommandNonOptionsData
|
||||||
| ApplicationCommandChannelOptionData
|
| ApplicationCommandChannelOptionData
|
||||||
| ApplicationCommandChoicesData
|
| ApplicationCommandChoicesData
|
||||||
|
| ApplicationCommandAutocompleteOption
|
||||||
| ApplicationCommandNumericOptionData
|
| ApplicationCommandNumericOptionData
|
||||||
| ApplicationCommandSubCommandData;
|
| ApplicationCommandSubCommandData;
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import {
|
|||||||
CommandInteraction,
|
CommandInteraction,
|
||||||
CommandInteractionOption,
|
CommandInteractionOption,
|
||||||
CommandInteractionOptionResolver,
|
CommandInteractionOptionResolver,
|
||||||
CommandOptionChoiceResolvableType,
|
|
||||||
CommandOptionNonChoiceResolvableType,
|
CommandOptionNonChoiceResolvableType,
|
||||||
Constants,
|
Constants,
|
||||||
ContextMenuInteraction,
|
ContextMenuInteraction,
|
||||||
@@ -447,6 +446,66 @@ client.on('ready', async () => {
|
|||||||
// This is to check that stuff is the right type
|
// This is to check that stuff is the right type
|
||||||
declare const assertIsPromiseMember: (m: Promise<GuildMember>) => void;
|
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 => {
|
client.on('guildCreate', async g => {
|
||||||
const channel = g.channels.cache.random();
|
const channel = g.channels.cache.random();
|
||||||
if (!channel) return;
|
if (!channel) return;
|
||||||
@@ -820,12 +879,6 @@ declare const applicationNonChoiceOptionData: ApplicationCommandOptionData & {
|
|||||||
applicationNonChoiceOptionData.choices;
|
applicationNonChoiceOptionData.choices;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare const applicationChoiceOptionData: ApplicationCommandOptionData & { type: CommandOptionChoiceResolvableType };
|
|
||||||
{
|
|
||||||
// Choices should be available.
|
|
||||||
applicationChoiceOptionData.choices;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare const applicationSubGroupCommandData: ApplicationCommandSubGroupData;
|
declare const applicationSubGroupCommandData: ApplicationCommandSubGroupData;
|
||||||
{
|
{
|
||||||
assertType<'SUB_COMMAND_GROUP' | ApplicationCommandOptionTypes.SUB_COMMAND_GROUP>(
|
assertType<'SUB_COMMAND_GROUP' | ApplicationCommandOptionTypes.SUB_COMMAND_GROUP>(
|
||||||
|
|||||||
Reference in New Issue
Block a user