types: Strengthen autocomplete option types (#6950)

Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
Suneet Tipirneni
2021-11-11 13:38:34 -05:00
committed by GitHub
parent 9f240ea0d1
commit 7630158f59
2 changed files with 74 additions and 8 deletions

View File

@@ -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>(