I have a construct like this:
interface Foo<T> {
value: T;
}
interface Bar<T> {
value: T;
}
function transform<T>(foos: Foo<T>[]): Bar<T> {
// ...
}
I want to call transform()
like this: transform([{ value: 'a' }, { value: 1 }])
and have that result in the type Bar<string | number>
. However, what actually happens in the code above is that the inferred type is string
and calling transform()
with the second array element results in an error because value
is a number
and not a string
. Is it possible to change this code to make it correctly infer the type string | number
?