isItemInArrayGuard<T>(item, array): item is T[number]
Checks if an item is in an array. Asserts that item is of the same type as union of array items.
Useful to prevent needing to assert an unknown value before checking if it is in a strongly typed array.
Type Parameters
T extends unknown[] | readonly unknown[]
Parameters
item: unknown
array: T
Returns item is T[number]
Example
`isItemInArrayGuard(someNumber, [1, 2, 3])`INSTEADOF`[1, 2, 3].includes(someNumber as [1, 2, 3][number])`
Checks if an item is in an array. Asserts that item is of the same type as union of array items. Useful to prevent needing to assert an unknown value before checking if it is in a strongly typed array.