Skip to content

Commit

Permalink
types(AutocompleteOption): backport fix and improve types (#8078)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImRodry committed Jun 13, 2022
1 parent 3095f35 commit 613fd43
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/structures/CommandInteractionOptionResolver.js
Expand Up @@ -240,10 +240,19 @@ class CommandInteractionOptionResolver {
return option?.message ?? null;
}

/**
* The full autocomplete option object.
* @typedef {Object} AutocompleteFocusedOption
* @property {string} name The name of the option
* @property {ApplicationCommandOptionType} type The type of the application command 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|ApplicationCommandOptionChoice}
* @returns {string|AutocompleteFocusedOption}
* The value of the option, or the whole option if getFull is true
*/
getFocused(getFull = false) {
Expand Down
16 changes: 14 additions & 2 deletions typings/index.d.ts
Expand Up @@ -837,8 +837,8 @@ export class CommandInteractionOptionResolver<Cached extends CacheType = CacheTy
): NonNullable<CommandInteractionOption<Cached>['member' | 'role' | 'user']> | null;
public getMessage(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['message']>;
public getMessage(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['message']> | null;
public getFocused(getFull: true): ApplicationCommandOptionChoiceData;
public getFocused(getFull?: boolean): string | number;
public getFocused(getFull: true): AutocompleteFocusedOption;
public getFocused(getFull?: boolean): string;
public getAttachment(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['attachment']>;
public getAttachment(
name: string,
Expand Down Expand Up @@ -4358,6 +4358,18 @@ export interface ConstantsClientApplicationAssetTypes {
BIG: 2;
}

export type AutocompleteFocusedOption = Pick<CommandInteractionOption, 'name'> & {
focused: true;
type:
| 'STRING'
| 'INTEGER'
| 'NUMBER'
| ApplicationCommandOptionTypes.STRING
| ApplicationCommandOptionTypes.INTEGER
| ApplicationCommandOptionTypes.NUMBER;
value: string;
};

export interface ConstantsColors {
DEFAULT: 0x000000;
WHITE: 0xffffff;
Expand Down

0 comments on commit 613fd43

Please sign in to comment.