microsoft / microsoft/TypeScript
Import assignment should work with esnext targets
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Search Terms
import assignment
Suggestion
#22321 was closed by a bot that thought the issue was addressed, but it wasn't.
Import assignment should work with esnext targets
Use Cases
JS modules loaders for Node might not support importing CJS with import statements, so you would use require to import them. But we'd still like to bring in their types. This is what import assignment is designed for, it's just disallowed with esnext targets.
Examples
This:
import * as m from './a-module.js';
import cjs = require('some-cjs');
should emit:
import * as m from './a-module.js';
const cjs = require('some-cjs');
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript / JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. new expression-level syntax)
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
No files or tests are named. Start by tracing TypeScript's import-assignment handling for esnext targets, then compare the current output with the issue's example; the work is done when the assignment emits a require-based declaration while preserving the existing import.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100