Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 928 Bytes

File metadata and controls

47 lines (35 loc) · 928 Bytes

typelab / utils / ArrayShift

type ArrayShift<T> = T extends WritableArray ? _IfNotAnyOrNever<T, T extends [Any?, ...(infer U)] ? U : T> : never;

Removes the first element from an Writable Array type. If the Array is a Tuple, the result will be a new Tuple without the first element. If the Array is not a Tuple, the result will be the original Array type.

Type Parameters

Type Parameter Description

T

The Array type to shift from.

Returns

A new Array type with the first element removed.

Example

type Shifted = ArrayShift<[string, number]>; // [number]
type Same = ArrayShift<(string | number)[]>; // (string | number)[]
type Never1 = ArrayShift<readonly [string, number]>; // never
type Never2 = ArrayShift<any>; // never