ts-data-forge
    Preparing search index...
    • Casts an array to MaxLengthTuple<MaxLength, E> after checking that it has at most maxLength elements.

      This is the structural counterpart of asMaxLengthArray; see asFixedLengthTuple for when to prefer which.

      Type Parameters

      • MaxLength extends ArgArr

        The maximum number of elements (inclusive).

      • Xs extends readonly unknown[]

        The input array type (tuple types are preserved).

      Parameters

      • maxLength: MaxLength

        The maximum number of elements (inclusive).

      • xs: Xs

        The array to cast.

      Returns MaxLengthTuple<MaxLength, Xs[number]> & Xs

      xs typed as MaxLengthTuple<MaxLength, Xs[number]> & Xs.

      const tags = Arr.asMaxLengthTuple(8, ['a', 'b', 'c']);

      // curried version
      const asTags = Arr.asMaxLengthTuple(8);

      // Arr.asMaxLengthTuple(2, ['a', 'b', 'c']); // throws TypeError

      If xs.length > maxLength.

    • Casts an array to MaxLengthTuple<MaxLength, E> after checking that it has at most maxLength elements.

      This is the structural counterpart of asMaxLengthArray; see asFixedLengthTuple for when to prefer which.

      Type Parameters

      • MaxLength extends ArgArr

        The maximum number of elements (inclusive).

      Parameters

      • maxLength: MaxLength

        The maximum number of elements (inclusive).

      Returns <Xs extends readonly unknown[]>(
          xs: Xs,
      ) => MaxLengthTuple<MaxLength, Xs[number]> & Xs

      xs typed as MaxLengthTuple<MaxLength, Xs[number]> & Xs.

      const tags = Arr.asMaxLengthTuple(8, ['a', 'b', 'c']);

      // curried version
      const asTags = Arr.asMaxLengthTuple(8);

      // Arr.asMaxLengthTuple(2, ['a', 'b', 'c']); // throws TypeError

      If xs.length > maxLength.