microsoft / microsoft/TypeScript

Import assignment should work with esnext targets

Open
#24,992 12 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs Proposal
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.