Description
TypeScript Version: 2.02
Expected behavior:
I have a const enum in typescript:
const enum LogLevel {
TRACE = 0,
DEBUG = 1,
INFO = 2,
WARN = 3,
ERROR = 4,
SILENT = 5
}
Based on the typescript spec the following field:
private foo: number = LogLevel.DEBUG;
should be compiled as:
this.foo = 1 /* DEBUG */;
Actual behavior:
When I use tsc from the command line (Windows) it works as expected. But when it is compiled with awesome-typescript-loader in a webpack project (which uses the typescript.js from node_modules as opposed to the tsc.js which is used by tsc), then the enum constant is not getting inlined:
this.foo = LogLevel.DEBUG;
It turned out it was caused by the declaration
option in tsconfig.json. If it is set to false, the two compilations produce the above inconsistent result. But when it is set to true, it works as expected. Not sure why this flag has such an effect on the outcome.
I created a github project where the problem is reproducible.
https://github.com/akosbordas/typescript-enum-issue
After you changed the declaration
flag you just have to run ng build
and check the main.bundle.js in dist folder.