Skip to content

Using import type... generates export {}; into the JS fileΒ #60074

@bpasero

Description

@bpasero

πŸ”Ž Search Terms

esm module import export

πŸ•— Version & Regression Information

This reproduces with version 5.6

⏯ Playground Link

https://www.typescriptlang.org/play/?module=7#code/JYWwDg9gTgLgBDAnmApnAVHAhgZzgIyyjgDMoIQ4ByEiCKgbgCgmBjAG1zwDE64BvFnGFwwUYADcsMNDJwwAFAEoBTEevYp4WAFxwAdgFcQ+FFGbqRWOAF4EAC2A4AdKwphDM5RZEBfNu6eKMp6RiZmqjD25ADuBihxAKJQ5FAKAEQAslr2EAAmBhDwoGCaICj6MnnO6UrM-qxQWDHsypHREHH6CXDJqRnZUfmFxeBlFVU1dUz+vkA

πŸ’» Code

import type * from 'foo';

class Foo {

    private test() {
       let a: number;
       a = this.compute();
    }
compute(): number {
throw new Error("Method not implemented.");
}
crawl() {
throw new Error("Method not implemented.");
}
}

πŸ™ Actual behavior

There is a export {}; at the end of the JS file.

πŸ™‚ Expected behavior

import type should have no side-effects on the generated JS.

Additional information about the issue

The issue here is that this forces the JS file to be ESM when it maybe is not. This makes it hard to convert from JS to TS where in JS I have more control over this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions