When I have a function which accepts an array of a generic type and return a transformed array, I could write:
function myfun<T>(input: Array<T>): Array<T> {}
However this fails if the array is of heterogeneous type, since T is then different over the array. Now since I know that T will always be a subtype of a certain base: BaseTy
and during the function I only use functions from/that operate on the base type, I could write:
function myfun(input: Array<BaseTy>): Array<BaseTy> {}
However this has the problem that the actual type is "lost" and the array is thus no longer a heterogeneous array of the derived type.
Can this be fixed in flow without resorting to unsafe typecasts or any
?