microsoft / microsoft/TypeScript
map through enum
Open
Nobody has claimed this yet.
Needs Proposal
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.1.6
Search Terms: enum
Code
enum ABC {
A = 'A',
B = 'B',
C = 'C',
}
// No Error
for (const key in ABC) {
console.log(ABC[key]);
}
// Error: Element implicitly has an 'any' type because index expression is not of type 'number'
Object.keys(ABC).map(key => console.log(ABC[key]));
Expected behavior:
Object.keys, values, entries on enum ABC infer type of ABC's key and value.
Actual behavior:
Cannot get inferred type.
Shouldn't type of key from enum be 'A' | 'B' | 'C'?
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 enum and Object.keys example from the issue with TypeScript 3.1.6, then compare the inferred types for the for-in and Object.keys cases. The work is done when Object.keys, values, and entries provide the expected enum key and value types without an implicit-any error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100