I have the following class method:
or<T extends (() => any)[]>(rules: T): ReturnType<T[number]> {
for (const rule of rules) {
try {
return this.call(rule);
} catch (_) {
continue;
}
}
throw new Error("no rule matched");
}
I want it to work such that e.g. or([() => "a", () => 1]) would be of type string | number. Currently the inference is not working correctly and I'm just getting any.
Any ideas on getting this to work?