microsoft / microsoft/TypeScript
Poor error recovery when `enum` is used as a parameter name
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.6.2
Search Terms: expression expected reserved word
Code
function converter<Enum>(values: string[], enums: Enum[]): Map<Enum, string> {
return new Map<Enum, string>(
enums.map((enum: Enum, index: number) => [ enum, values[index] ])
);
}
Expected behavior:
After some confusion why this displays so many red curlies, the error should make it clear to me that the reserved word enum is accidentaly being used as an argument name. An error is given on enum saying something along the lines of You cannot use enum as a variable/argument because it is a reserved word.
Actual behavior:
After a LOT of confusion, one realizes that the reserved word enum is accidentally being used as an argument name. An error is given on several parts in the above code, where the most helpful one is Expression expected (ts1109), which is just unnecesarily confusing.
Related Issues:
None that seem related.
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
Reproduce the diagnostic with the provided code in the TypeScript 3.6.2 Playground, then compare the parser's errors around the enum parameter name. Improve the reported error so it identifies the reserved-word misuse without producing confusing cascading diagnostics, and verify the result against the same example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100