Skip to content

Commit

Permalink
types(AutocompleteOption): fix and improve types (#8069)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImRodry committed Jun 13, 2022
1 parent 10a6c42 commit 476b7d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 10 additions & 3 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,8 +1007,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): AutocompleteOption;
public getFocused(getFull?: boolean): string | number;
public getFocused(getFull: true): AutocompleteFocusedOption;
public getFocused(getFull?: boolean): string;
}

export class ContextMenuCommandInteraction<Cached extends CacheType = CacheType> extends CommandInteraction<Cached> {
Expand Down Expand Up @@ -4064,7 +4064,14 @@ export interface CommandInteractionResolvedData<Cached extends CacheType = Cache
attachments?: Collection<Snowflake, Attachment>;
}

export type AutocompleteOption = Pick<CommandInteractionOption, 'name' | 'type' | 'value' | 'focused'>;
export type AutocompleteFocusedOption = Pick<CommandInteractionOption, 'name'> & {
focused: true;
type:
| ApplicationCommandOptionType.String
| ApplicationCommandOptionType.Integer
| ApplicationCommandOptionType.Number;
value: string;
};

export declare const Colors: {
Default: 0x000000;
Expand Down

0 comments on commit 476b7d5

Please sign in to comment.