Skip to content

Latest commit

 

History

History
91 lines (62 loc) · 1.31 KB

File metadata and controls

91 lines (62 loc) · 1.31 KB

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 Parameters

Type Parameter Default type Description

Target extends ReadonlyArray

The Array to be overwritten.

Source extends ReadonlyArray

[]

The Array to be assigned to the Target.

Z extends _LookupType

"shallow"

Defines the lookup type, which can be 'deep' or 'shallow', defaults to 'shallow'.

Returns

A new Array type that overwrites Target elements with Source elements.

Example

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'>;