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 Parameter | Default type | Description |
|---|---|---|
T | - | The type to check |
U | T | Internal parameter for comparison (defaults to T) |
Example
ts
type A = IsUnion<string | number>; // true
type B = IsUnion<string>; // false