Flow analysis doesn't work with es6 collections 'has' method
See original GitHub issueTypeScript Version: 2.1.1
Code
const x = new Map<string, string>();
x.set("key", "value");
if (x.has("key")) {
const y : string = x.get("key"); // error: y is string | undefined, not string
}
Expected behavior: y is narrowed down to string Actual behavior: y is still string | undefined even after checking if the map has that key
Issue Analytics
- State:
- Created 7 years ago
- Reactions:123
- Comments:18 (4 by maintainers)
Top Results From Across the Web
javascript - FlowType Does Not Recognize ES6 Function Import
This error is generated when executing "yarn run flow". This same code compiles and executes without issue. – Nathan G. Jan 11, 2018...
Read more >You Don't Know JS: ES6 & Beyond - GitHub Pages
An iterator is a structured pattern for pulling information from a source in one-at-a-time fashion. This pattern has been around programming for a...
Read more >Control flow and error handling - JavaScript - MDN Web Docs
Here, { x++; } is the block statement. This outputs 2 because the var x statement within the block is in the same...
Read more >ECMAScript® 2023 Language Specification - TC39
◢5.2 Algorithm Conventions ... 6.1.7.1 Property Attributes; 6.1.7.2 Object Internal Methods and Internal Slots ... 8.1 RS: Evaluation; ◢8.2 Scope Analysis.
Read more >You Don't Know JS: ES6 & Beyond
Async Flow Control. ... “You Don't Know JavaScript: ES6 & Beyond by Kyle Simpson ... function declaration was the immediately invoked function expres‐....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@DanielRosenwasser I think you’re a bit overcomplicating the stuff.
Anyway, these all are workarounds. What’s need to be fixed if flow analysis.
Actually, you can get this to work better with another overload.