ts-fortress
    Preparing search index...

    Type Alias BoundedLengthTuple<Min, Max, Elm>

    BoundedLengthTuple: TuplePrefixesDownTo<MakeTuple<Max, Elm>, Min>

    Creates a readonly tuple type whose length is between Min and Max (both inclusive). The result is a union of fixed-length readonly tuples MakeTuple<Min, Elm> | ... | MakeTuple<Max, Elm>. Requires Min and Max to be non-negative integer literals with Min <= Max.

    Type Parameters

    • Min extends number

      The minimum length (inclusive). Must be a non-negative integer literal.

    • Max extends number

      The maximum length (inclusive). Must be a non-negative integer literal.

    • Elm

      The type of elements in the tuple.

    A union of readonly tuples whose lengths range from Min to Max.

    type T = BoundedLengthTuple<1, 3, string>;
    // readonly [string] | readonly [string, string] | readonly [string, string, string]
    const a: T = ['a']; // ok
    const b: T = ['a', 'b', 'c']; // ok
    // const c: T = []; // Error
    // const d: T = ["a", "b", "c", "d"]; // Error