mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
types: Strengthen autocomplete option types (#6950)
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
@@ -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