ts-fortress
    Preparing search index...

    Type Alias ArrayAtMostLen<N, Elm>

    ArrayAtMostLen: ArrayBoundedLen<0, N, Elm>

    Creates a readonly tuple type whose length is at most N (i.e. 0 to N, both inclusive). Counterpart of ArrayAtLeastLen, defined as ArrayBoundedLen<0, N, Elm>. The result is a union readonly [] | readonly [Elm] | ... | MakeTuple<Elm, N>. Requires N to be a non-negative integer literal.

    Type Parameters

    • N 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 0 to N.

    type AtMost2Numbers = ArrayAtMostLen<2, number>;
    // readonly [] | readonly [number] | readonly [number, number]
    const valid: AtMost2Numbers = []; // ok
    const alsoValid: AtMost2Numbers = [1, 2]; // ok
    // const invalid: AtMost2Numbers = [1, 2, 3]; // Error