Really don't get it

This commit is contained in:
Dragon Fire
2024-03-24 00:35:44 -04:00
parent 88f2c99f67
commit ebb1facd68
+2 -1
View File
@@ -16,6 +16,7 @@ module.exports = class ArgumentUnionType extends ArgumentType {
async validate(val, msg, arg) {
let results = this.types.map(type => !type.isEmpty(val, msg, arg) && type.validate(val, msg, arg));
results = await Promise.all(results);
console.log(results);
if (results.some(valid => valid && typeof valid !== 'string')) return true;
const errors = results.filter(valid => typeof valid === 'string');
if (errors.length > 0) return errors.join('\n');
@@ -25,9 +26,9 @@ module.exports = class ArgumentUnionType extends ArgumentType {
async parse(val, msg, arg) {
let results = this.types.map(type => !type.isEmpty(val, msg, arg) && type.validate(val, msg, arg));
results = await Promise.all(results);
console.log(results);
for (let i = 0; i < results.length; i++) {
if (results[i] && typeof results[i] !== 'string') return this.types[i].parse(val, msg, arg);
console.log(results[i], typeof results[i]);
}
throw new Error(`Couldn't parse value "${val}" with union type ${this.id}.`);
}