-
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
Fix #25172: Add narrowing for unknown
with triple equals
#26941
Fix #25172: Add narrowing for unknown
with triple equals
#26941
Conversation
c2ab8f6
to
a8cc939
Compare
Shall I revive this and remerge master? |
Not many people seem to have run into this recently, but if you're still interested in adding the feature just shout and I can check it works with master. |
@jack-williams please revive, I'm back from leave now and am trying to get the PR backlog moving again. A fresh rebase with master would be great |
a8cc939
to
6f30537
Compare
@RyanCavanaugh done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - great testcase btw. Will merge on Tuesday after the release branch finalizes
Great, and thank you! |
Technically a breaking change, better bump the major version of TS 🙄 declare const u: unknown;
if (u === 0) {
let m = u;
// Now an error
m = "";
} (don't actually change anything) |
Fixes #25172.
Narrows an identifier of type
unknown
when strict compared (===
) with a value of primitive, non-primitive, or object type.object
.Limitations.
==
because we would need to consider coercion rules.number & "age"
make it hard to tell the actual runtime type. We could inherit the intersection type but this might violate branding expectations.