Skip to content

IsUnion<T, U>

ts
type IsUnion<T, U> = T extends unknown ? [U] extends [T] ? false : true : never;

Defined in: types.ts:41

Determines whether a type is a union type (has multiple constituents).

Type Parameters

Type ParameterDefault typeDescription
T-The type to check
UTInternal parameter for comparison (defaults to T)

Example

ts
type A = IsUnion<string | number>; // true
type B = IsUnion<string>; // false