mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
refactor: remove conditional autocomplete option return types (#7396)
Co-authored-by: Almeida <almeidx@pm.me>
This commit is contained in:
@@ -20,7 +20,7 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends s
|
|||||||
* @param name The name of the choice
|
* @param name The name of the choice
|
||||||
* @param value The value of the choice
|
* @param value The value of the choice
|
||||||
*/
|
*/
|
||||||
public addChoice(name: string, value: T): Omit<this, 'setAutocomplete'> {
|
public addChoice(name: string, value: T): this {
|
||||||
if (this.autocomplete) {
|
if (this.autocomplete) {
|
||||||
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
|
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends s
|
|||||||
*
|
*
|
||||||
* @param choices The choices to add
|
* @param choices The choices to add
|
||||||
*/
|
*/
|
||||||
public addChoices(choices: [name: string, value: T][]): Omit<this, 'setAutocomplete'> {
|
public addChoices(choices: [name: string, value: T][]): this {
|
||||||
if (this.autocomplete) {
|
if (this.autocomplete) {
|
||||||
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
|
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
|
||||||
}
|
}
|
||||||
@@ -62,11 +62,7 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends s
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setChoices<Input extends [name: string, value: T][]>(
|
public setChoices(choices: [name: string, value: T][]): this {
|
||||||
choices: Input,
|
|
||||||
): Input extends []
|
|
||||||
? this & Pick<ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T>, 'setAutocomplete'>
|
|
||||||
: Omit<this, 'setAutocomplete'> {
|
|
||||||
if (choices.length > 0 && this.autocomplete) {
|
if (choices.length > 0 && this.autocomplete) {
|
||||||
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
|
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
|
||||||
}
|
}
|
||||||
@@ -83,11 +79,7 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends s
|
|||||||
* Marks the option as autocompletable
|
* Marks the option as autocompletable
|
||||||
* @param autocomplete If this option should be autocompletable
|
* @param autocomplete If this option should be autocompletable
|
||||||
*/
|
*/
|
||||||
public setAutocomplete<U extends boolean>(
|
public setAutocomplete(autocomplete: boolean): this {
|
||||||
autocomplete: U,
|
|
||||||
): U extends true
|
|
||||||
? Omit<this, 'addChoice' | 'addChoices'>
|
|
||||||
: this & Pick<ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T>, 'addChoice' | 'addChoices'> {
|
|
||||||
// Assert that you actually passed a boolean
|
// Assert that you actually passed a boolean
|
||||||
booleanPredicate.parse(autocomplete);
|
booleanPredicate.parse(autocomplete);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user