devtypes - v2.1.0
    Preparing search index...

    Type Alias StaticListLengthConstraint<T, N>

    StaticListLengthConstraint: T extends readonly any[]
        ? If<Equals<T["length"], N>, T, never>
        : never

    Validate a tuple or readonly tuple has an exact fixed length.

    Type Parameters

    • T extends readonly any[]

      Tuple type to validate

    • N extends number

      Required tuple length

    This will check if the length of the tuple T is exactly N. If it is, this resolves to T. If it is not, this resolves to never, effectively enforcing a compile-time constraint on the tuple length.

    type ExactFive = StaticListLengthConstraint< [ 1, 2, 3, 4, 5 ], 5 >;  // [ 1, 2, 3, 4, 5 ]
    type NotFive = StaticListLengthConstraint< [ 1, 2, 3 ], 5 >; // never