bugfixes / improvements

ensure preservation of potentially extended class during cloning
resolver private -> protected to allow use in class extensions
This commit is contained in:
Erik 2023-08-16 14:06:06 +03:00
parent 471c749ce4
commit 6d0e55a0f4
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68

View File

@ -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;