Skip to content

assertcheck v1.0.0


assertcheck / assert / all

Function: all()

ts
function all<T, U>(
   arr, 
   predicate, 
   opts?): asserts arr is U[];

Defined in: src/assert.ts:872

Asserts that every element satisfies the predicate — Ruby all?.

Type Parameters

Type Parameter
T
U

Parameters

ParameterType
arrT[]
predicate((v) => v is U) | ((v) => boolean)
opts?Opts

Returns

asserts arr is U[]

Remarks

When the predicate is a type guard (v: T) => v is U, the entire array is narrowed to U[] after the call.

Example

ts
assert.all(orders, o => o.status === "paid", "all orders must be paid")

// With type guard — narrows array type:
assert.all(items, (v): v is string => typeof v === "string")
items // string[]

Released under the Apache 2.0 License. Built by Vagabond Studio — senior-only for growing companies.