-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed as not planned
Closed as not planned
Copy link
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
π Search Terms
Exhaustiveness checking
π Version & Regression Information
TS 5.5, v5.6.0-dev.20240729
β― Playground Link
π» Code
// ok
function x1(y: {z: '123'} | {z: '234'}) {
switch(y.z) {
case '123':
break;
case '234':
break;
default:
((_:never)=>{})(y);
break;
}
}
function x2(y: {z: '123'}) {
switch(y.z) {
case '123':
break;
default:
((_:never)=>{})(y); // error, y is treated as { z: '123'; } here
break;
}
}
// ok
function x3(y: '123') {
switch(y) {
case '123':
break;
default:
((_:never)=>{})(y);
break;
}
}
π Actual behavior
function 'x2' get an error : Argument of type '{ z: "123"; }' is not assignable to parameter of type 'never'.
π Expected behavior
Compile pass, because function 'x1' shows that TS can narrow the parent type and 'x3' shows that TS can narrow non-union type
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created