Bring typeof switch behaviour inline with if#27182
Closed
jack-williams wants to merge 10 commits intomicrosoft:masterfrom
Closed
Bring typeof switch behaviour inline with if#27182jack-williams wants to merge 10 commits intomicrosoft:masterfrom
jack-williams wants to merge 10 commits intomicrosoft:masterfrom
Conversation
Collaborator
Author
|
I'm tempted to re-open this PR with a fresh one to tidy up all the history into a single commit. Just give me a thumbs up / response and I'll sort it out, link to the new one, and close this. |
typeof switch behaviour inline with if
typeof switch behaviour inline with ifb4344f7 to
88a4fdf
Compare
Contributor
|
@jack-williams @RyanCavanaugh - will this PR remove the compile error from the code below? Or will it only affect // compiled with strictNullChecks
function repro (x: string[] | null) {
switch (x && x.length) {
case 1:
console.log (x[0]); // compiler error: Object is possibly null
break;
default:
console.log ('invalid x');
break;
}
if (x && x.length===1) {
console.log (x[0]); // no compiler error
} else {
console.log ('invalid x');
}
} |
Collaborator
Author
You're right, this PR will only affect |
Contributor
|
OK thanks @jack-williams. After some more searching, it looks like the problem I ran into was #24091. |
Collaborator
Author
|
Closing in favour of #27680 |
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.
This PR has now morphed into something that bundles a couples of changes to essentially bring
switchnarrowing inline withif, which was recently updated in two keys ways:unknownnarrowing for"function"and"object"I don't know if this PR should be split in separate requests tackling different issues. This can probably be resolved after the release of 3.1 when 3.2 is more relevant.
Fixes #27180
Fixes #27335
Adds tests for #27181