microsoft / microsoft/TypeScript

Poor error recovery when `enum` is used as a parameter name

Open
#33,931 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: Error Messages
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.

Playground Link

Related Issues:
None that seem related.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.