Closed
Description
TypeScript Version: Version 2.6.0-dev.20170914
Code
function test() {
type YesNo = ('No' | 'Yes');
let answer: YesNo = 'No'; // Bug disappears after adding 'as YesNo'.
try {
answer = 'Yes';
return; // Bug disappears after removing the return.
} finally {
if (answer === 'Yes') { // Bug: Operator === cannot be applied to types 'No' and 'Yes'
} else if (answer === 'No') {
}
}
}
Expected behavior:
No compilation errors.
Actual behavior:
Compilation error:
bug.ts(8,13): error TS2365: Operator '===' cannot be applied to types '"No"' and '"Yes"'.
Note:
This bug is similar to "Erroneous control flow type narrowing in loops": #15835