Function atW

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

It produces the same wide type as the "at" method of the source array.

at

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
  • Parameters

    • position: number

    Returns <S extends readonly unknown[]>(source: S) => undefined | S[number]