Closed
Description
Bug Report
π Search Terms
Searched for 'undefined' in issues after 4.3
π Version & Regression Information
- This changed between versions 4.2.3, and 4.3.2
β― Playground Link
Note that the error is show for all 4.1, 4.2 and 4.3. But pasting the same code into a project using 4.1.5 does NOT show the error.
π» Code
let problem: {a:number} | undefined;
function setValue(){
problem= {a:10};
}
// reset
// _this causes compiler to belive that 'problem' can only be undefined from now on
problem = undefined;
// call other method that can do anything
setValue();
if (problem) {
_// compiler says that 'problem' is undefined and Property 'a' does not exist on type 'never'_
console.log(problem.a)
}
π Actual behavior
compiler says that 'problem' is undefined and Property 'a' does not exist on type 'never'
π Expected behavior
Expected compiler to know that 'problem could be both undefined and {a:number}
Metadata
Metadata
Assignees
Labels
No labels