Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 791 Bytes

File metadata and controls

56 lines (40 loc) · 791 Bytes

typelab / utils / ArrayAt

type ArrayAt<T, Index> = T extends ReadonlyArray ? _IfNotAnyOrNever<T, PropValue<T, Index>> : never;

Extracts the type of an element at a specific index from an Array type.

Type Parameters

Type Parameter Description

T

The Array type to extract from.

Index

The index of the element to extract.

Returns

The type of the element at index I from type T.

Example

type ElementAt = ArrayAt<[string, number, boolean], 1>; // number
type Undefined = ArrayAt<[string, number, boolean], 3>; // undefined
type Never = ArrayAt<any, 1>; // never