ts-type-forge
    Preparing search index...
    IsFixedLengthList: number extends T["length"] ? false : true

    Checks if a given readonly array type T has a fixed length (i.e., is a tuple). Returns true if T is a tuple, false if it's a regular array (Type[]).

    It works by checking if the general number type is assignable to the specific length property of T. For tuples, T['length'] is a specific number literal (e.g., 3), and number is not assignable to 3. For regular arrays, T['length'] is number, and number is assignable to number.

    Type Parameters

    • T extends readonly unknown[]

      The readonly array or tuple type to check.

    true if T is a tuple (fixed length), false otherwise.

    type IsTuple = IsFixedLengthList<[1, 2, 3]>; // true
    type IsArray = IsFixedLengthList<number[]>; // false
    type IsReadonlyArray = IsFixedLengthList<readonly string[]>; // false
    type IsEmptyTuple = IsFixedLengthList<[]>; // true
    type IsTupleWithRest = IsFixedLengthList<[number, ...string[]]>; // false