assertArrayItem()function

assertArrayItem(arr: PossibleArray<T>, item: unknown, caller: AnyCaller = assertArrayItem): asserts item is T
ParamType
arrPossibleArray<T>
The array or iterable to search. required
itemunknown
The value to look for. required
callerAnyCaller
Function to attribute a thrown error to (defaults to assertArrayItem itself). Defaults to assertArrayItem
Return
asserts item is T
Throws
RequiredError
If item does not exist in arr.

Assert that an unknown value is an item in a specified array.

Examples

assertArrayItem([1, 2, 3], 2); // (passes)
assertArrayItem([1, 2, 3], 9); // throws RequiredError