Relative Content

Tag Archive for typescriptunion-typesdiscriminated-union

Discriminating typescript union by parameter that is a union itself

I have an object that can have multiple types that can be discriminated through the “type” property. I want to write a function that would take a type as a parameter and return correctly typed item or undefined, depending if the initial object is currently the correct type, as follows: