-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Strict null check flow analysis broken by unrelated branch logic #36028
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
Comments
Simplified type PendingRequest = {
pending: true;
response: string | null;
}
type IdleRequest = {
pending: false;
response: string | null;
}
declare const request: PendingRequest | IdleRequest;
function someFlow() {
if (request.response) {
if (request.pending) { } // <-- induces error in following line
request.response.toUpperCase();
}
} |
This is a known design limitation. In a property access |
Is that out-of-scope (so this issue should be closed) or "just" very hard to do and it will take a while (so the issue can stay open to get notifications on the progress). Thank you very much for looking into that. |
We'd have to totally rethink CFA, so there are no immediate plans in this area. |
So, turns out we don't really need this restriction after all. See #36114. |
You're my hero of the week @ahejlsberg. Thank you so much for such a quick response. Also super interesting to see that this was fixed by removing an old workaround. |
TypeScript Version: 3.8.0-dev.20200104
Search Terms:
flow, branch, unrelated
Code
Expected behavior:
someFlow2
works just likesomeFlow
.Actual behavior:
someFlow2
contains an unhandled null case.Playground Link:
Click me!
Related Issues:
#9998 is about trade-offs in flow analysis, but I'm not sure if this case is a bug or known tradeoff. At least for me it was unexpected.
The text was updated successfully, but these errors were encountered: