When checking that a variable is one of possible values, my team uses the following:
const status: 400 | 404 | 500;
if ([400, 404].includes(status)) {
// status should be 400 | 404
}
Maybe we can add a type guard override for Array.includes such that when the second argument (fromIndex) is not specified, it tests that searchElement is one of the array values.
Something like:
interface ReadonlyArray<T> {
includes(searchElement: unknown): searchElement is T;
// ... default type
}
When checking that a variable is one of possible values, my team uses the following:
Maybe we can add a type guard override for
Array.includes
such that when the second argument (fromIndex) is not specified, it tests thatsearchElement
is one of the array values.Something like:
Is this feasible?