Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 585 Bytes

File metadata and controls

44 lines (32 loc) · 585 Bytes

typelab / utils / ArrayLength

type ArrayLength<T> = T extends ReadonlyArray ? _IfNotAnyOrNever<T, T["length"]> : never;

Extracts the length of an Array type.

Type Parameters

Type Parameter Description

T

The target Array.

Returns

The length of type T.

Example

type Length = ArrayLength<[1, 2, 3]>; // 3
type Length2 = ArrayLength<string[]>; // number
type Never = ArrayLength<any>; // never