Skip to content

Latest commit

 

History

History
77 lines (53 loc) · 1.17 KB

File metadata and controls

77 lines (53 loc) · 1.17 KB

typelab / utils / ArrayAssign

type ArrayAssign<Target, Source> = _ArrayAssign<Target, Source>;

Assign the elements of Source into Target.

It's like ObjectAssign but for Array only.

  • If Target is readonly, it returns Target as is. In order to follow the actual result of Object.assign.
  • If either Target or Source is not an Array or Tuple, it returns Target as is.

Type Parameters

Type Parameter Default type Description

Target extends ReadonlyArray

‐

The target Array or Tuple.

Source

[]

The Array or Tuple to be assigned to the Target.

Returns

A new Array or Tuple combining elements from both Target and Source.

Example

// [0, 1, 2]
type Result1 = ArrayAssign<[1, 2], [0, 1, 2]>;

// (string | number)[]
type Result2 = ArrayAssign<string[], number[]>;

// readonly [1, 2]
type Result3 = ArrayAssign<readonly [1, 2], [0, 1, 2]>;