Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

transpileModule: not preserving exports #54526

Closed
acutmore opened this issue Jun 5, 2023 · 0 comments · Fixed by #54799
Closed

transpileModule: not preserving exports #54526

acutmore opened this issue Jun 5, 2023 · 0 comments · Fixed by #54799
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@acutmore
Copy link
Contributor

acutmore commented Jun 5, 2023

Bug Report

The output of transpileModule did not preserve the value exports from the input module when the identifier also matches a type. This does not happen when compiling the project using tsc or with verbatimModuleSyntax enabled.

🔎 Search Terms

  • transpileModule
  • exports
  • preserve

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about module emit.

⏯ Playground Link

Playground link with relevant code

Interestingly the error that is appearing in the playground

Import declaration conflicts with local declaration of 'Component'.(2440)

Is not appearing for the same code in VSCode for a repo version of the issue: https://github.com/acutmore/transpile-module-bug

💻 Code

// exports.ts
import fooValue from "./values";
import type {Foo} from "./types";

const Foo: Foo = fooValue as any as Foo;

export {Foo};
import tsc from "typescript";
import * as fs from "node:fs";

const result = tsc.transpileModule(fs.readFileSync("./exports.ts", "utf-8"), {
    compilerOptions: {
        "verbatimModuleSyntax": false,
        "importsNotUsedAsValues": "error",
        "ignoreDeprecations": "5.0",
        "module": "ESNext"
    }
});

🙁 Actual behavior

import fooValue from "./values";
var Foo = fooValue;

🙂 Expected behavior

import fooValue from "./values";
var Foo = fooValue;
export { Foo };
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants