Relative Content

Tag Archive for typescriptgenericstypescript-genericsunion-typesreferential-transparency

Substituting Type into TypeScript Generic gives different type

I want to write a TypeScript type based on a union such that each member of the union is transformed a certain way if it matches a certain shape, and is otherwise discarded. In working on this, I found that in TypeScript, the result of applying a type to a generic is different than substituting that type into the body of the generic in place of the type parameter. For example: