You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When checking that a variable is one of possible values, my team uses the following:
conststatus: 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:
interfaceReadonlyArray<T>{includes(searchElement: unknown): searchElement is T;// ... default type}
Is this feasible?
The text was updated successfully, but these errors were encountered:
Danoha
changed the title
Type Array.filter as a type guard
Type Array.includes as a type guard
Aug 27, 2024
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?
The text was updated successfully, but these errors were encountered: