Fix #25172: Add narrowing for unknown with triple equals#26941
Merged
RyanCavanaugh merged 5 commits intomicrosoft:masterfrom Jan 30, 2019
Merged
Fix #25172: Add narrowing for unknown with triple equals#26941RyanCavanaugh merged 5 commits intomicrosoft:masterfrom
unknown with triple equals#26941RyanCavanaugh merged 5 commits intomicrosoft:masterfrom
Conversation
c2ab8f6 to
a8cc939
Compare
Collaborator
Author
|
Shall I revive this and remerge master? |
Collaborator
Author
|
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. |
Member
|
@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
Collaborator
Author
|
@RyanCavanaugh done! |
RyanCavanaugh
approved these changes
Jan 25, 2019
Member
RyanCavanaugh
left a comment
There was a problem hiding this comment.
LGTM - great testcase btw. Will merge on Tuesday after the release branch finalizes
Collaborator
Author
|
Great, and thank you! |
Member
|
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #25172.
Narrows an identifier of type
unknownwhen 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.