bugfixes / improvements
ensure preservation of potentially extended class during cloning resolver private -> protected to allow use in class extensions
This commit is contained in:
parent
471c749ce4
commit
6d0e55a0f4
@ -26,7 +26,7 @@ class CommandOption implements ICommandOption {
|
||||
value?: unknown;
|
||||
aliased = false;
|
||||
strict: boolean;
|
||||
private resolver?: IResolver | undefined;
|
||||
protected resolver?: IResolver | undefined;
|
||||
|
||||
constructor (def: CommandOptionDefinition|CommandOption|ICommandOption) {
|
||||
|
||||
@ -90,7 +90,9 @@ class CommandOption implements ICommandOption {
|
||||
}
|
||||
|
||||
clone (rawValue?: string[], resolver?: IResolver): CommandOption {
|
||||
const opt = new CommandOption(this);
|
||||
// Call own constructor, important to do it like this in order to preserve any potentially extended classes
|
||||
// eslint-disable-next-line new-parens, no-extra-parens
|
||||
const opt = new (this.constructor(this) as new () => typeof this);
|
||||
opt.rawValue = rawValue;
|
||||
opt.resolver = resolver;
|
||||
return opt;
|
||||
@ -98,7 +100,7 @@ class CommandOption implements ICommandOption {
|
||||
|
||||
async parse (guild?: unknown): Promise<ParseResult> {
|
||||
if (!this[OptionType[this.type]])
|
||||
throw new Error(`Missing parsing function for ${this.type}`);
|
||||
throw new Error(`Missing parsing function for ${OptionType[this.type]}`);
|
||||
if (typeof this[OptionType[this.type]] !== 'function')
|
||||
throw new Error(`Expected function type for member ${OptionType[this.type]}`);
|
||||
this.guild = guild;
|
||||
|
Loading…
Reference in New Issue
Block a user