typelab / utils / ArrayUnionize
type ArrayUnionize<Target, UnionType, Z> = IsArray<Target> extends true ? _ArrayUnionize<Target, UnionType, Z> : never;Unions the elements of an Array with a specified UnionType, creating a new Array where each element
is either the original element or the UnionType.
This type will unionize all nested Array types (if Z is 'deep').
| Type Parameter | Default type | Description |
|---|---|---|
|
|
‐ |
The |
|
|
‐ |
The type to union with each element of the |
|
|
|
Defines the lookup type, which can be |
// [string | number, number | [number, boolean]]
type Shallow = ArrayUnionize<[string, [number, boolean]], number, 'shallow'>;
// [string | number, [number, number | boolean]]
type Deep = ArrayUnionize<[string, [number, boolean]], number, 'deep'>;