mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 11:03:30 +01:00
typings(ApplicationCommandOptionData): Align command data options types more with discord API (#6247)
* types(ApplicationCommandData): align command data more with discord API * types(ApplicationCommandData): clean up type definitions a bit * types(ApplicationCommandData): fix issue where could be used with and * types(ApplicationCommandOptionData): make subcommand option stronger * test(ApplicationCommandOptionData): add typing tests
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
import {
|
||||
ApplicationCommand,
|
||||
ApplicationCommandChoicesData,
|
||||
ApplicationCommandData,
|
||||
ApplicationCommandManager,
|
||||
ApplicationCommandNonOptionsData,
|
||||
ApplicationCommandOptionData,
|
||||
ApplicationCommandResolvable,
|
||||
ApplicationCommandSubCommandData,
|
||||
ApplicationCommandSubGroupData,
|
||||
CacheFactory,
|
||||
Caches,
|
||||
CategoryChannel,
|
||||
@@ -13,6 +18,8 @@ import {
|
||||
CommandInteraction,
|
||||
CommandInteractionOption,
|
||||
CommandInteractionOptionResolver,
|
||||
CommandOptionChoiceResolvableType,
|
||||
CommandOptionNonChoiceResolvableType,
|
||||
Constants,
|
||||
DMChannel,
|
||||
Guild,
|
||||
@@ -56,6 +63,7 @@ import {
|
||||
User,
|
||||
VoiceChannel,
|
||||
} from '.';
|
||||
import { ApplicationCommandOptionTypes, ApplicationCommandTypes } from './enums';
|
||||
|
||||
const client: Client = new Client({
|
||||
intents: Intents.FLAGS.GUILDS,
|
||||
@@ -628,6 +636,40 @@ declare const applicationCommandManager: ApplicationCommandManager;
|
||||
);
|
||||
}
|
||||
|
||||
declare const applicationNonChoiceOptionData: ApplicationCommandOptionData & {
|
||||
type: CommandOptionNonChoiceResolvableType;
|
||||
};
|
||||
{
|
||||
// Options aren't allowed on this command type.
|
||||
|
||||
// @ts-expect-error
|
||||
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>(
|
||||
applicationSubGroupCommandData.type,
|
||||
);
|
||||
assertType<ApplicationCommandSubCommandData[] | undefined>(applicationSubGroupCommandData.options);
|
||||
}
|
||||
|
||||
declare const applicationSubCommandData: ApplicationCommandSubCommandData;
|
||||
{
|
||||
assertType<'SUB_COMMAND' | ApplicationCommandOptionTypes.SUB_COMMAND>(applicationSubCommandData.type);
|
||||
|
||||
// Check that only subcommands can have no subcommand or subcommand group sub-options.
|
||||
assertType<(ApplicationCommandChoicesData | ApplicationCommandNonOptionsData)[] | undefined>(
|
||||
applicationSubCommandData.options,
|
||||
);
|
||||
}
|
||||
|
||||
declare const guildApplicationCommandManager: GuildApplicationCommandManager;
|
||||
assertType<Promise<Collection<Snowflake, ApplicationCommand>>>(guildApplicationCommandManager.fetch());
|
||||
assertType<Promise<Collection<Snowflake, ApplicationCommand>>>(guildApplicationCommandManager.fetch(undefined, {}));
|
||||
|
||||
Reference in New Issue
Block a user