Skip to content

Latest commit

 

History

History
49 lines (35 loc) · 698 Bytes

File metadata and controls

49 lines (35 loc) · 698 Bytes

typelab / utils / ArrayFirst

type ArrayFirst<T> = T extends ReadonlyArray ? _IfNotAnyOrNever<T, T[0]> : never;

Extracts the type of the first element of an Array type.

Type Parameters

Type Parameter Description

T

The Array type to extract from.

Returns

The type of the first element from type T.

Example

// string
type FirstElement = ArrayFirst<[string, number, boolean]>;

// string | number | boolean
type AllElements = ArrayFirst<(string | number | boolean)[]>;

// never
type Never = ArrayFirst<any>;