Skip to content

const enum imports are stripped even with isolatedModules #40499

Closed
@nayeemrmn

Description

@nayeemrmn

First of all, isolatedModules seems to imply preserveConstEnums but it doesn't look like this is documented: https://www.typescriptlang.org/tsconfig#isolatedModules.


Repro:

tsconfig.json:

{
  "compilerOptions": {
    "target": "esnext",
    "isolatedModules": true
  }
}

temp2.ts:

export const enum a {
  b = 1,
  c = 2,
};

temp.ts:

import { a } from "./temp2";
console.log(a.b);

temp2.js (enum is generated, so preserveConstEnums is implied?):

export var a;
(function (a) {
    a[a["b"] = 1] = "b";
    a[a["c"] = 2] = "c";
})(a || (a = {}));
;

temp.js (the import is left out, even though no inlining is done??):

console.log(a.b);
export {};

This module is invalid and will throw a reference error at runtime. Expected the import from the TS source to be preserved.


I've checked that the same thing will happen with preserveConstEnums specified explicitly. The equivalent issue occurs without "target": "esnext".

Version 3.8.3.

Ref denoland/deno#7326 (comment).

cc @bartlomieju @lucacasonato @kitsonk

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