You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
After you changed the declaration flag you just have to run ng build and check the main.bundle.js in dist folder.
The text was updated successfully, but these errors were encountered:
akosbordas
changed the title
enums are not compiled as number when declaration flag is false in tsconfig.json
enums are not compiled as numbers when declaration flag is false in tsconfig.json
Sep 28, 2016
This is an issue with how awesome-typescript-loader is using the compiler API.
awesome-typescript-loader uses the TypeScript transpileModule function in "fast mode"; "fast mode" is enabled when the declaration flag is not set. transpileModule does a pure syntactic transform of each file; in this mode, const enums are not resolved (because its a per-file transform) and their values are not inlined.
transpileModuleshould not be used unless an error-free compilation of the same sources has occurred under the --isolatedModules flag, which verifies that it is safe to use transpileModule on a particular compilation.
I would log a bug with awesome-typescript-loader -- their behavior here is not sound. Hopefully there's some way to configure it to not use transpileModule?
TypeScript Version: 2.02
Expected behavior:
I have a const enum in typescript:
Based on the typescript spec the following field:
should be compiled as:
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:
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 runng build
and check the main.bundle.js in dist folder.The text was updated successfully, but these errors were encountered: