Closed
Description
TypeScript Version: 2.5.2 / nightly (2.6.0-dev.20170921)
Code
File foo.ts exports a const enum + a function:
export const enum ConstFooEnum {
Some,
Values,
Here
};
export function fooFunc(): void { /* removed */ }
File index.ts which imports Foo.ts but uses only the const enum values:
import * as Foo from "./foo";
function check(x: Foo.ConstFooEnum): void {
switch (x) {
case Foo.ConstFooEnum.Some:
break;
}
}
Expected behavior:
Generated Javascript code should not require("./foo")
. Docu (http://www.typescriptlang.org/docs/handbook/modules.html) indicates that type only imports should not result in a require()
.
Actual behavior:
Generated JS code contains line var Foo = require("./foo");
even Foo
is not used anywhere.
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Foo = require("./foo");
function check(x) {
switch (x) {
case 0 /* Some */:
break;
}
}
In above simple code sample I can workaround the issue by doing importing only the ConstFooEnum
via import { ConstFooEnum } from "./foo";
but if the enum is inside some namespace (e.a. enum gets re-exported from an inner module) it's not that easy.