-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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 non-null assertion lost inside Array#map callback #10982
Comments
This is working as intended. The type checker knows that The suggested way to do this is to copy Also see #8849. |
Thanks for the explanation. So the proper fix here would be to teach the type checker that Array#map/forEach are just sugar for a loop, similar to how an IIFE is just sugar for a block. |
Well, possibly. Even knowing that the callback is only called before |
TypeScript Version: nightly (2.1.0-dev.20160919)
Code
Expected behavior:
There should be no compile errors, as
foo.bar
is guaranteed to be non-null inside the whole blockActual behavior:
Inside the map callback, TS thinks that
foo.bar
can be null. Strangely enough, an IIFE works just fine.The text was updated successfully, but these errors were encountered: