microsoft / microsoft/TypeScript
"Import assignment cannot be used when targeting ECMAScript modules." should come with a codefix
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.2.0-dev.20181030
Code
a.ts
import abs = require("abs");
tsconfig.json
{
"compilerOptions": {
"target": "esnext"
}
}
The error message is Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.. This indicates that we could provide a code fix.
Expected behavior:
There is a codefix that offers to change this to import abs from "abs";, or import * as abs from "abs";. If --esModuleInterop is set and the imported value is not used only as a namespace, we should prefer a default import.
Actual behavior:
No codefix.
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 a.ts and the shown tsconfig.json, then trace the compiler's codefix handling for this error. The fix should offer default and namespace import forms, preferring a default import when esModuleInterop is enabled and the value is not used only as a namespace; verify both suggested edits and their applicability.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100