Closed as not planned
Closed as not planned
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