type ArrayLast<T> = T extends ReadonlyArray ? _IfNotAnyOrNever<T, T extends readonly [...Any, infer Last] ? Last : T[number]> : never;Extracts the type of the last element of an Array type.
| Type Parameter | Description |
|---|---|
|
|
The |
The type of the last element from type T, or never if empty.
// boolean
type LastElement = ArrayLast<[string, number, boolean]>;
// string | number | boolean
type AllElements = ArrayLast<(string | number | boolean)[]>;
// never
type Never = ArrayLast<any>;