TypeScript Version: 3.7.0-dev.20190919
Search Terms:
variable, type inference, narrowed, lost
Code
let a: boolean = false;
const modifyA = (): void => {
a = true;
};
modifyA();
if (a) { // a is inferred as false
console.log('a is true');
}
I'm not sure if it can lead to something bad inside typescript, but it creates problem for typescript-eslint (check related issue).
Expected behavior:
a is inferred as boolean
Actual behavior:
a is inferred as false
Related Issues:
https://github.com/typescript-eslint/typescript-eslint/issues/989
Duplicate of https://github.com/microsoft/TypeScript/issues/9998
Sure, sorry for duplicate
Most helpful comment
Duplicate of https://github.com/microsoft/TypeScript/issues/9998