Skip to content

Latest commit

 

History

History
64 lines (45 loc) · 916 Bytes

File metadata and controls

64 lines (45 loc) · 916 Bytes

typelab / utils / ArrayUnshift

type ArrayUnshift<T, U> = T extends WritableArray ? _IfNotAnyOrNever<T, IfNever<U, T, [U, ...T]>> : never;

Adds a new element to the beginning of an Writable Array type.

Type Parameters

Type Parameter Description

T

The Array type to unshift into.

U

The element type to add to the front of the Array.

Returns

A new Array type with the element U added to the front.

Example

// [boolean, string, number]
type Unshifted = ArrayUnshift<[string, number], boolean>;

// [string, number]
type Same = ArrayUnshift<[string, number], never>;

// never
type Never1 = ArrayPush<readonly [string, number], string>;

// never
type Never2 = ArrayPush<any, string>;