typelab / utils / ArrayOverwrite
type ArrayOverwrite<Target, Source, Z> = IsArray<Target | Source> extends true ? _ArrayOverwrite<Target, Source, Z> : never;Overwrite elements of Target with elements of Source.
This type will overwrite all nested Array types (if Z is 'deep').
| Type Parameter | Default type | Description |
|---|---|---|
|
|
‐ |
The |
|
|
[] |
The |
|
|
|
Defines the lookup type, which can be |
A new Array type that overwrites Target elements with Source elements.
type Arr1 = [string, [string, string]];
type Arr2 = [number, [number], number];
// [number, [number], number]
type Shallow = ArrayOverwrite<Arr1, Arr2, 'shallow'>;
// [number, [number, string], number]
type Deep = ArrayOverwrite<Arr1, Arr2, 'deep'>;