Extracts the numeric index type from a readonly array or tuple type T.
If T is a tuple (fixed length), it returns a union of its numeric index literals (e.g., 0 | 1 | 2).
If T is a regular array (variable length), it returns number.
Type Parameters
Textendsreadonlyunknown[]
The readonly array or tuple type.
Returns
A union of number literals representing the indices if T is a tuple, otherwise number.
Example
typeTupleIndices = IndexOfTuple<[string, boolean, number]>; // 0 | 1 | 2 typeArrayIndices = IndexOfTuple<string[]>; // number typeEmptyTupleIndices = IndexOfTuple<[]>; // never typeReadonlyArrayIndices = IndexOfTuple<readonlynumber[]>; // number
Extracts the numeric index type from a readonly array or tuple type
T. IfTis a tuple (fixed length), it returns a union of its numeric index literals (e.g.,0 | 1 | 2). IfTis a regular array (variable length), it returnsnumber.