API Reference / @evolu/common / Assert / assertNonEmptyArray

Variable: assertNonEmptyArray()

const assertNonEmptyArray: <T>(arr, message?) => asserts arr is [T, ...T[]];

Defined in: packages/common/src/Assert.ts:63

Asserts that an array is non-empty.

Ensures the provided array has at least one element, helping TypeScript infer the array as non-empty when this is logically guaranteed but not statically known.

Example

assertNonEmptyArray([1, 2, 3]); // no-op
assertNonEmptyArray([]); // throws Error

Type Parameters

Type Parameter
T

Parameters

ParameterType
arrT[]
message?string

Returns

asserts arr is [T, ...T[]]

Was this page helpful?