Closed
Description
TypeScript Version: 3.4.5
Search Terms:
Code
let aaa: string | null;
function getAaa(): string {
if (aaa === null) { aaa = 'hello'; }
return aaa;
}
console.log(getAaa().length);
Expected behavior:
I expected a compile error (when using --strict). Something like this:
error TS2454: Variable 'aaa' is used before being assigned.
Actual behavior:
No compile error. But got this runtime error:
Cannot read property 'length' of undefined
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
nmain commentedon May 2, 2019
See #28013
typescript-bot commentedon May 11, 2019
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.