Type alias SizedTuple<T, N, Acc>

SizedTuple<T, N, Acc>: N extends Integer<infer M>
    ? Acc["length"] extends M
        ? Acc
        : SizedTuple<T, M, [T, ...Acc]>
    : never

Represents a tuple of size N, where N is a Numeric type. The tuple's length is exactly N, with each element of the tuple being of type T.

Type Parameters

  • T

    The type of the elements in the tuple.

  • N extends Numeric

    The desired length of the tuple.

  • Acc extends T[] = []

    Accumulator type for recursive construction.

Example

SizedTuple<string, 3>; // Result: [string, string, string]
SizedTuple<number, 2>; // Result: [number, number]
SizedTuple<number, 0>; // Result: []

See

Tuple