Fixed type narrowing in switch statements with parenthesized expressions - #56035
Merged
Jake Bailey (jakebailey) merged 1 commit intoOct 9, 2023
Merged
Conversation
Contributor
|
Ah, you beat me to it :) I would have thought it was something like this. Thanks for providing the fix (and the incredible work you do for TypeScript, really) |
Contributor
Author
|
Thanks :) |
Jake Bailey (jakebailey)
approved these changes
Oct 9, 2023
Member
|
I merged this, but I should have run the tests. In light of #56020, is there a problem here in JS code which casts the argument to a switch (/** @type { "a" | "b" } */ (foo)) {
case "a":
return;
default: {
const x: "b" = foo;
}
} |
Member
|
Ah, yes, you should be using: |
Member
|
Hm, I can't seem to make a test case where this fails. I thought this would show a difference but it does not: // @strict: true
// @noEmit: true
// @checkJs: true
// @allowJs: true
// @filename: index.js
let value = "";
switch (/** @type {"foo" | "bar"} */ (value)) {
case "bar":
value;
break;
case "foo":
value;
break;
case "invalid":
value;
break;
}(namely, I would have expected |
|
Mateusz Burzyński (@Andarist) I saw this in my email and thought it was Emotion, congratulations on being a TypeScript contributor!!1! |
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 #56030