microsoft / microsoft/TypeScript
Flow analysis doesn't work with es6 collections 'has' method
Open
Nobody has claimed this yet.
Awaiting More Feedback
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided TypeScript 2.1.1 example with Map.has and Map.get, then trace the compiler's control-flow analysis for ES6 collection methods. Done means the value returned by get is narrowed to string inside the has check without breaking related narrowing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100