ts-fortress
    Preparing search index...

    Type Alias ArrayBoundedLen<Min, Max, Elm>

    ArrayBoundedLen: TuplePrefixesDownTo<MakeTuple<Elm, Max>, 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<Elm, Min> | ... | MakeTuple<Elm, Max>. 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 = ArrayBoundedLen<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