We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
Playground Link: https://www.typescriptlang.org/play/#src=let%20aaa%3A%20string%20%7C%20null%3B%0D%0A%0D%0Afunction%20getAaa()%3A%20string%20%7B%0D%0A%20%20%20%20if%20(aaa%20%3D%3D%3D%20null)%20%7B%0D%0A%20%20%20%20%20%20%20%20aaa%20%3D%20'hello'%3B%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20return%20aaa%3B%0D%0A%7D%0D%0A%20%0D%0A%0D%0Aconsole.log(getAaa().length)%3B
The text was updated successfully, but these errors were encountered:
See #28013
Sorry, something went wrong.
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
No branches or pull requests
TypeScript Version: 3.4.5
Search Terms:
Code
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
Playground Link: https://www.typescriptlang.org/play/#src=let%20aaa%3A%20string%20%7C%20null%3B%0D%0A%0D%0Afunction%20getAaa()%3A%20string%20%7B%0D%0A%20%20%20%20if%20(aaa%20%3D%3D%3D%20null)%20%7B%0D%0A%20%20%20%20%20%20%20%20aaa%20%3D%20'hello'%3B%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20return%20aaa%3B%0D%0A%7D%0D%0A%20%0D%0A%0D%0Aconsole.log(getAaa().length)%3B
The text was updated successfully, but these errors were encountered: