Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 910 Bytes

File metadata and controls

47 lines (35 loc) · 910 Bytes

typelab / utils / ArrayPop

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

Removes the last element from an Writable Array type. If the Array is a Tuple, the result will be a new Tuple without the last 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 pop from.

Returns

A new Array type with the last element removed.

Example

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