-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
narrowing to null via typeguards doesn't work #27634
Comments
You'd need #9252 to do this |
jfc, no country for an old man |
@RyanCavanaugh is there any way to accomplish this up to your knowledge? |
Maybe? export function isNull<T extends (null extends T ? any : never)>(value: T): value is Extract<T,null> {
return value === null;
} |
|
I was going to suggest this: export function isNull<T extends (null extends T ? any : never)>(value: T): value is T & null {
return value === null;
} But |
@ahejlsberg your way ( |
@Aleksey-Bykov Can you post an example of one that doesn't work? |
@jack-williams hm, i guess i am taking my words back, now it looks working just as well not sure what happened, but when i applied it first time i didn't get narrowing that i expected if i see it again i will let you know |
broken now: #29662 |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow. |
i am hacking my way around this limitation #11920
so my goal is to make sure that
isNull
only applied toT | null
types and by this i mean thatnull
must be a valid case of a given type (types that don't have| null
must not be permitted), i am trying to use conditional types to enforce it, this is what i gotunfortunately it doesn't work and i am clueless what i am doing wrong, it looks like a bug
@ahejlsberg you might want to look at it
The text was updated successfully, but these errors were encountered: