-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JS EmitThe issue relates to the emission of JavaScriptThe issue relates to the emission of JavaScriptHelp WantedYou can do thisYou can do this
Milestone
Description
TypeScript Version: 3.8.0-dev.20191216
Search Terms: const enum import export preserveConstEnums
Code
MyEnum.ts
const enum MyEnum {
FirstValue,
SecondValue
}
export default MyEnum;ImportExportInNamespace.ts
import _MyEnum from "./MyEnum";
export namespace MyNamespace {
export import MyEnum = _MyEnum;
}App.ts
import { MyNamespace } from "./ImportExportInNamespace";
console.log(MyNamespace.MyEnum.FirstValue);Compile the above using
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"preserveConstEnums": true
}
}Expected behavior:
ImportExportInNamespace.ts compiles to
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var MyEnum_1 = require("./MyEnum");
var MyNamespace;
(function (MyNamespace) {
MyNamespace.MyEnum = MyEnum_1.default;
})(MyNamespace = exports.MyNamespace || (exports.MyNamespace = {}));Actual behavior:
ImportExportInNamespace.ts wrongly compiles to
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var MyNamespace;
(function (MyNamespace) {
MyNamespace.MyEnum = MyEnum_1.default;
})(MyNamespace = exports.MyNamespace || (exports.MyNamespace = {}));i.e. we are missing
var MyEnum_1 = require("./MyEnum");If I change the enum not to be a const the code compiles correctly. I'm using it as a workaround.
Related Issues:
#23514
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JS EmitThe issue relates to the emission of JavaScriptThe issue relates to the emission of JavaScriptHelp WantedYou can do thisYou can do this