ts-data-forge
    Preparing search index...
    • Casts an array to MinLengthTuple<1, E> after checking that it has at least one element.

      This is the structural counterpart of asNonEmptyArray, and the length-1 specialization of asMinLengthTuple.

      Type Parameters

      • Xs extends readonly unknown[]

        The input array type (tuple types are preserved).

      Parameters

      • xs: Xs

        The array to cast.

      Returns readonly [Xs[number], Xs[number]] & Xs

      xs typed as MinLengthTuple<1, Xs[number]> & Xs.

      const values = Arr.asNonEmptyTuple([1, 2, 3]);

      const first: number = values[0]; // OK — no `undefined`

      // Arr.asNonEmptyTuple([]); // throws TypeError

      If xs is empty.