Simplification of constraining TypeScript’s type parameters to “ground” instantiations

This is a simplification of my code suggested in How to constrain in TypeScript type parameters to “ground” instantiations of union types

Matthias Falk
Aug 4, 2021

Within the auxiliary type IsMemberOrSubtypeOfAComponent the first condition [T] extends [Union] is redundant. The inner condition true extends ConjunctionOfExplicitComponentChecks suffices. As a result we can do without this auxiliary type at all and refactor type IsOneOf to:

type IsOneOf<T, Union> =
true extends EqualsOneOfTheComponents<T, Union>
? true
: false;

Here is the modified TypeScript Playground.

--

--