Skip to content

atOrThrow

ts
function Array.atOrThrow<T>(
    target: readonly T[],
    offset: number,
): Exclude<T, null | undefined>

Returns the value at the specified offset, throws an exception if the offset was out of range, or the retrieved value was nullable.

Example

ts
import { Array } from "@monstermann/array";

Array.atOrThrow([1, null], -1); // Error
ts
import { Array } from "@monstermann/array";

pipe([1, null], Array.atOrThrow(-1)); // Error