-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Control flow analysis for element access with variable index doesn't account for async race condition #58822
Comments
This is a duplicate of #9998; see also the many other duplicates linked from that issue. |
But this is a regression as 5.4.5 would not make the optimistic type narrowing on this path. |
How is this relevant to computed keys at all? Your code would have the same unsoundness if you substitute all |
It's not about computed keys. I just took the example from this blog and extended a bit. The main concern is that when there's an |
Which is exactly what #9998 is about. And it's unrelated to |
The analogy for a synch function would be an intervening function call that causes the same mutation. This issue is Exhibit A of "why TS team was so hesitant to add narrowing by indexed access for so long". The bottom line is the compiler doesn't know whether any given |
Maybe worth mentioning the tradeoffs in the blog post. I read the blog post and felt it might not be as reliable as it seems. Which is why I wrote this issue. I don't think I would be the only one with this thought. |
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
Control flow analysis async race condition
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.5.1-rc#code/IYZwngdgxgBAZgV2gFwJYHsIwOYFNkBywAtrgBQCUAXDAAoBO6xqIuAPCMvahNgHwwA3gCgYYmPXwJ6WAOQB3dPQA2AE1kBuYQF9hw0JFiIUGLHACMZdACMAVjQBKuKEtUcuPbABoYZMgA8aTm5eChgAXgEAN3RUVTCAHxgkVVw4HlxVPh8Aa1wwII9QoVFxVDhfZDAAB1x0CptbAG08sABdCPDwmAAiYyg0TB6wkXExmBcIThgIElwImGB5YFRkHHwiUkotcfFGlvy2slnSCh3xXTH91o7ulLSM1S1dYUnp1oXZbEl8T01XzDTRoLUbiA7tY5zQohbDUGAxOIlXZiN7oZS4AB0ynQ2DIAAMABK4ZTYnwAEkEJ1w2gAhHizqUxLoXgwmCxMcASWQmhYrHZcvkKD5eY0BWAKG0GUA
π» Code
π Actual behavior
No type error, but runtime failure:
π Expected behavior
Type checker should account for potential race condition and do not persist the narrowed type after an
await
statement.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: