Skip to content

transpileModule: not preserving exports #54526

Closed
@acutmore

Description

@acutmore

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 };

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions