-
Notifications
You must be signed in to change notification settings - Fork 19
Add constraints to type parameters of Has
#14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@younho9 have you taken a look at the type definition of const allowedLocales = [
'us-en',
'ca-en',
'ca-fr',
] as const
function isAcceptedLocale<T extends typeof allowedLocales[number]>(locale:T): locale is T {
return allowedLocales.includes(locale)
}
const myLocale = 'us-en'
if(isAcceptedLocale(myLocale)) {
assert<Has<typeof myLocale, typeof allowedLocales[number]>>(true)
}
else {
assert(true)
} Based on your first example I think it should be true, because I'm trying to assert the typeguard will respond to the expected structure. However, based on your second example, I can see the need for more strictness given the typical testing structure of Not saying there's not a solution, but it might need an entire rewrite of the lib, if it is possible at all. |
Whelp. I played around a little more and looked at more examples in the current lib (and other issue comments). I think I've found a solution to ensure the interface of If we do this I noticed a few other functions seem to not really follow the "result === expectation" (left to right) thinking, so a PR should include tweaks to their direction as well. Not to mention this would most certainly be a breaking change (major bump) |
Because typescript doesn't support strict version of Extract for union types. (microsoft/TypeScript#31474)
How about add constraints to type parameters of
Has
?current behavior
Suggestion
The text was updated successfully, but these errors were encountered: