Function at

Returns the element at the specified position in the source array.

It tries to infer the type of the element at the specified position. When not possible, it produces the same wide type as the "at" method of the source array.

at(0)([1, 2, 3]); // 1 with type number
at(1)([1, 2, 3] as const); // 2 with literal type 2
at(-1)([1, 2, 3] as const); // 3 with literal type 3
  • Type Parameters

    • P extends number

    Parameters

    • position: P

    Returns (<S>(source: S) => At<P, S>)

      • <S>(source): At<P, S>
      • Type Parameters

        • S extends readonly unknown[]

        Parameters

        • source: S

        Returns At<P, S>