microsoft / microsoft/TypeScript

Import ellision emit bug: usage of imports only in keys of interfaces does not result in those imports being elided as type-only

Open
#58,081 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: JS Emit Help Wanted
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 Search Terms

import ellision emit

🕗 Version & Regression Information
  • This is the behavior in every version I tried - I saw it in typescript 4.9 and in the playground in typescript 5.4.3.
⏯ Playground Link

https://www.typescriptlang.org/play?importHelpers=true&target=99&module=2#code/JYWwDg9gTgLgBAbwEIEEBKBfOAzKERwDkARgIZSEDcAsAFCiSxwBUcpAzjhBDngYdm5U6dAKYAPRvGAA7GKKjZSAY1Fw03GAGUYpeYjpw4AbVRoAugC447GFFkBzGrSPHBEAHRkoVm3cfOGHRAA

💻 Code
import {BAR} from 'bar';
import * as foo from 'foo';

export interface RootState {
  [BAR]: string;
  [foo.bar]: string;
}
🙁 Actual behavior

When compiled to ESNext module:

import { BAR } from 'bar';
import * as foo from 'foo';

when compiled to AMD with importHelpers it's interesting that __importStar appears

define(["require", "exports", "tslib", "bar", "foo"], function (require, exports, tslib_1, bar_1, foo) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    foo = tslib_1.__importStar(foo);
});
🙂 Expected behavior

output should be an entirely empty module, e.g. AMD should be

define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
});

ESNext should be

export {}
Additional information about the issue

No response

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 linked TypeScript Playground and the minimal imports/interfaces example, then compare the ESNext and AMD outputs with the reported behavior. Done means imports used only in interface keys are elided, producing export {} for ESNext and an AMD module with only require and exports.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.