-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
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
strictNullChecks false positive when all possible conditions have been defined #27909
Comments
This is a design limitation: control-flow analysis (used by strictNullChecks as well as some other TypeScript features) isn't aware of exhaustiveness of |
Alright, I see. Hope this will implemented in some way. Right now this is inconvenient to assign default value when it makes no sense and usage of |
@mattmccutchen I'm curious why noImplicitReturns can detect such exhaustiveness, while strictNullChecks can't... Surely, if it's possible to detect for a return, it should be possible for variable initialization? |
@lemoinem |
TypeScript Version:
v3.1.3
Search Terms:
strictNullChecks, switch, case, condition, if, variable is used before being assigned.
Code
Expected behavior:
No errors here.
TS should know about all possible checks. Right now we can get some kind of error:
Not all code paths return a value.
in cases when we didn't define all possiblecase
s or whendefault
has been omited.Actual behavior:
We got an error
Variable is used before being assigned
. It also happens withif-else-if
variant.Playground Link:
Click Me!
Related Issues:
Possible related issue: #27239. But this one is out of the loop.
Also: #9655, #10470, #17358, #20409, #23271.
The text was updated successfully, but these errors were encountered: