ts-type-forge
    Preparing search index...
    IndexOfTuple: IndexOfTupleImpl<T, keyof T>

    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

    • T extends readonly unknown[]

      The readonly array or tuple type.

    A union of number literals representing the indices if T is a tuple, otherwise number.

    type TupleIndices = IndexOfTuple<[string, boolean, number]>; // 0 | 1 | 2
    type ArrayIndices = IndexOfTuple<string[]>; // number
    type EmptyTupleIndices = IndexOfTuple<[]>; // never
    type ReadonlyArrayIndices = IndexOfTuple<readonly number[]>; // number