I'm currently writing typings for a function that takes in an array of Clazz<U> objects, and returns an array of U. U isn't always identical between all the arguments.
Is it possible to set the return type to an array of all the values of U?
I've tried a variety of things including various usages of keyof and typeof, but simply doing so within the typings doesn't seem to give any results. The U-typed value of each Clazz item is accessed via a call to (instanceof Clazz).value.
Example function: (actual code in context on GitHub)
function example(input: Array<Clazz<U>>): Array<U> {
const out = [];
for(const item of input) {
out.push(item.value); // where item.value instanceof U === true
}
return out;
}
Ideal outcomes:
// if this is possible it would be fantastic!
example([new Clazz('this is a string'), new Clazz(500)]); // output type: [string, number]
// a union is acceptable!
example([new Clazz('this is a string'), new Clazz(500)]); // output type: Array<string | number>
Tis a class? That's a weird class name (usuallyTis used as a type parameter). This isn't quite a minimal reproducible example without a definition ofT(external links don't count) but I guess it's just something with avalueproperty.