Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove conditional autocomplete option return types #7396

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends s
* @param name The name 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) {
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
}
Expand Down Expand Up @@ -51,7 +51,7 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends s
*
* @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) {
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
}
Expand All @@ -62,11 +62,7 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends s
return this;
}

public setChoices<Input extends [name: string, value: T][]>(
choices: Input,
): Input extends []
? this & Pick<ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T>, 'setAutocomplete'>
: Omit<this, 'setAutocomplete'> {
public setChoices(choices: [name: string, value: T][]): this {
if (choices.length > 0 && this.autocomplete) {
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
}
Expand All @@ -83,11 +79,7 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends s
* Marks the option as autocompletable
* @param autocomplete If this option should be autocompletable
*/
public setAutocomplete<U extends boolean>(
autocomplete: U,
): U extends true
? Omit<this, 'addChoice' | 'addChoices'>
: this & Pick<ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T>, 'addChoice' | 'addChoices'> {
public setAutocomplete(autocomplete: boolean): this {
// Assert that you actually passed a boolean
booleanPredicate.parse(autocomplete);

Expand Down