Relative Content

Tag Archive for typescripttypestypescript-typingstypescript-generics

Why does type inference via generic function parameter to return type not work

I had a specific function to map from an array to a single item. Now that I want to map it based on the discriminator so I am trying to implement a more generic function.
I have a function with input parameter of a union type which have a discriminator.
Another parameter is the discriminator of the union[‘type’]. Why cant typescript infer the return type based on that parameter? I struggle to find an explanation.