microsoft / microsoft/TypeScript

ts error should better explain that import is a reserved keyword for a function name

Open
#28,648 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: Error Messages Effort: Moderate Experience Enhancement 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:
import
import keyword
keyword
Code

given the following code with a function named import 😞 :

export function	import(pad_id: number, config: Config, csvRows: string[][], externalCallback: (err?: Error | null, data?: string[]) => void) {
...

image

Expected behavior:

A clear error message explaining that import is a reserved keyword

Actual behavior:

A cryptic error message telling that there's a missing semicolumn :

image

Playground Link:

Related Issues:

didn't found any

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

Start with the supplied TypeScript snippet containing a function named import and reproduce the current diagnostic. Trace how the compiler parses this reserved keyword in that position, then update the diagnostic so it explains the restriction rather than reporting a missing semicolon. Confirm that the reported error is clearer without changing valid cases.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.