assertArrayItem()function
assertArrayItem(arr: PossibleArray<T>, item: unknown, caller: AnyCaller = assertArrayItem): asserts item is T
| Param | Type | |
|---|---|---|
arr | PossibleArray<T> | The array or iterable to search. required |
item | unknown | The value to look for. required |
caller | AnyCaller | 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