From 476b7d519c719152ea04e207f6dd09bb23e733db Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Mon, 13 Jun 2022 17:15:31 +0100 Subject: [PATCH] types(AutocompleteOption): fix and improve types (#8069) --- .../structures/CommandInteractionOptionResolver.js | 6 +++--- packages/discord.js/typings/index.d.ts | 13 ++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/discord.js/src/structures/CommandInteractionOptionResolver.js b/packages/discord.js/src/structures/CommandInteractionOptionResolver.js index 5449c4e18ea5..c28945f90bda 100644 --- a/packages/discord.js/src/structures/CommandInteractionOptionResolver.js +++ b/packages/discord.js/src/structures/CommandInteractionOptionResolver.js @@ -258,17 +258,17 @@ class CommandInteractionOptionResolver { /** * The full autocomplete option object. - * @typedef {Object} AutocompleteOption + * @typedef {Object} AutocompleteFocusedOption * @property {string} name The name of the option * @property {ApplicationCommandOptionType} type The type of the application command option - * @property {string|number} value The value of the option + * @property {string} value The value of the option * @property {boolean} focused Whether this option is currently in focus for autocomplete */ /** * Gets the focused option. * @param {boolean} [getFull=false] Whether to get the full option object - * @returns {string|number|AutocompleteOption} + * @returns {string|AutocompleteFocusedOption} * The value of the option, or the whole option if getFull is true */ getFocused(getFull = false) { diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 511bf0dd9d2f..9c310b1197ca 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1007,8 +1007,8 @@ export class CommandInteractionOptionResolver['member' | 'role' | 'user']> | null; public getMessage(name: string, required: true): NonNullable['message']>; public getMessage(name: string, required?: boolean): NonNullable['message']> | null; - public getFocused(getFull: true): AutocompleteOption; - public getFocused(getFull?: boolean): string | number; + public getFocused(getFull: true): AutocompleteFocusedOption; + public getFocused(getFull?: boolean): string; } export class ContextMenuCommandInteraction extends CommandInteraction { @@ -4064,7 +4064,14 @@ export interface CommandInteractionResolvedData; } -export type AutocompleteOption = Pick; +export type AutocompleteFocusedOption = Pick & { + focused: true; + type: + | ApplicationCommandOptionType.String + | ApplicationCommandOptionType.Integer + | ApplicationCommandOptionType.Number; + value: string; +}; export declare const Colors: { Default: 0x000000;