-
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
Type guards ignored in closure #38755
Comments
Asked on SO, doesn't get any response. Looks like a bug to me. |
Duplicate of #9998. |
Thanks |
On second thought this doesn’t seem to be a duplicate. key is locally defined, there is no way the addEventListener call can reset it back to null. Not sure it’s flow control related. |
This is a design limitation. When a local variable is declared with We could theoretically do more work in the control flow analyzer to determine that there are no assignments to a particular variable following the creation of a function closure that references the variable, but it's not trivial. |
TypeScript Version:
v4.0.0-dev.20200523
Search Terms:
type guard closure
Code
Expected behavior:
delete data[key]
contains no errorActual behavior:
delete data[key]
contains type errorPlayground Link:
https://www.typescriptlang.org/play/?#code/DYUwLgBAJghmMC4IG8DaBrJBnMAnAlgHYDmAutnkcQL4QC8K1AUAGYCuhAxmPgPaHQQoMCADyhAMLB8ndAAoAlCiYRVEYRHQgAnvQgsiUANI7FKtfhYQ5AQi3alyc2rW5wbXIQDcziMxca9gBMeva+AO6GvOEAdDBQUACiAG4ghGAAMvg4aSC4cgBEnNKyBQA01kp0AHzKLi5QQuAg0HAwGDpBpBAA9D0QYAAW2RAjvOi+DU0irfAd2t19A9oADi15uLy4FfYQnDACAEYthGzAwL7UCkzMrBzcfAIGhMamChQEJBAAPhCn53VXO5PH8zhdqEA
Related Issues:
The text was updated successfully, but these errors were encountered: