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.
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)
}
compiler says that 'problem' is undefined and Property 'a' does not exist on type 'never'
Bug Report
π Search Terms
Searched for 'undefined' in issues after 4.3
π Version & Regression Information
β― 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.
https://www.typescriptlang.org/play?ts=4.3.2&ssl=4&ssc=4&pln=17&pc=6#code/GYVwdgxgLglg9mABMOcAUBKRBvAUIgxAGwFMpEAHAJzgCNSBbALhwEMmwQHaSqBfRAB9E4ACYlgMMCVGIAvCLDjJ00QG5c+QqEiwEiAM5kAaqyIgSmPIRuUa9EgwXZ2ARgAMfDTb6abAen9EKhIjKC0CajpGeUVlKRkNCMRAxAgzIkQ4KAALXkQGMhy4WVzWcnSkUThEVjAAT1ypAHNksNNzSwwkmxhgRDQohwYsa1sCVIg4BgoYUipDVnqDRDLyAHIhxnXEGBWxCQTZOtkABRoKXih6xHXWHerQxDBsxBIADz3yfWvL2+kAG68dbJGxTMAGOCkAB0RDgzUG9kY0NYGGSvj4QA
π» Code
π 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}