The type to check.
type T1 = IsUnion<string | number>; // true
type T2 = IsUnion<string>; // false
type T3 = IsUnion<string | string>; // false (simplifies to string)
type T4 = IsUnion<never>; // false
type T5 = IsUnion<any>; // false
type T6 = IsUnion<unknown>; // false
type T7 = IsUnion<true | false>; // true (boolean)
type T8 = IsUnion<boolean>; // true (equivalent to true | false)
Checks if a given type
Uis a union type (contains more than one distinct type member).It works by distributing over the potential union members of
Uand comparing the original typeUwith each distributed memberM. IfUis a union, there will be at least oneMfor whichTypeEq<U, M>isfalse, causing the result for that branch to betrue. The final result becomestrueif any branch evaluates totrue. IfUis not a union,Mwill be the same asU,TypeEq<U, M>will betrue, and the result will befalse.Note:
never,any, andunknownare not considered unions by this type.