-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix switch-true case-true narrowing to behave equivalently to default case #59459
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
base: main
Are you sure you want to change the base?
Conversation
@typescript-bot test it |
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
@jakebailey Here are the results of running the user tests with tsc comparing Everything looks good! |
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@jakebailey Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
Would this also fix this function's return type being inferred as type Circle = {
kind: "circle";
radius: number;
};
type Square = {
kind: "square";
sideLength: number;
};
type Shape = Circle | Square;
function calculateArea(shape: Shape) {
switch (true) {
case shape.kind === "circle": {
return Math.PI * shape.radius * shape.radius;
}
case shape.kind === "square": {
return shape.sideLength * shape.sideLength;
}
}
} |
// @noEmit: true | ||
|
||
function uhoh(input: string) : "A"|"B"|"C" { | ||
switch (true) { |
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.
Awful, but, what about switch (false)
+ case false:
?
… case
Fixes #59133