-
Notifications
You must be signed in to change notification settings - Fork 179
Const enum are preserved and not replaced with actual values #137
Comments
I had a similar issue with the First if all (even in 2.x), it never inlines the (const) enum values, so you will end up with:
When Enum:
Webpack result with
Webpack result with
And because there is no export, the So basically, if you are using awesome-typescript-loader and (const) enums, you have to set note: it's a runtime error, so you might not notice it right away |
still a problem in any version > 0.17 it seems, including 1.1.1. const enums are supposed to be transpiled into their value, but instead are kept as is which causes runtime exceptions. preserveConstEnums doesnt do anything as we are not exporting the enums |
Please try |
Nope, putting that into tsconfig as below does not work. Tried both 1.1.1 and 0.19.1 "awesomeTypescriptLoaderOptions": { just to be clear i tried both true and false for disableFastEmit |
@s-panferov This still doesn't work in versions later than v0.16.2. |
@s-panferov I have come across this specific bug as well. It is causing me a bit of trouble with the @types/signalr types package. SignalR.ConnectionState is a const enum. Refer to: DefinitelyTyped/signalr/index.d.ts - Line 12 I have tried setting I should mention that I tried out a different TS compiler: gulp-typescript, and it transpiles const enum to the integer values as expected. Unfortunately it doesn't do any sort of advanced bundling like webpack. Would there happen to exist a work-around to get awesome-typescript-loader to replace const enum with their integer values? |
Any update / workaround for this issue? |
I've tried for days to get this to work. Pretty sure there is none. It's unfortunate given how old this issue is that there is not even a hack available. It is a devastating bug after all. Think of how many code bases are incorrectly being transpiled in the wild right now because of this. I know a large portion of the Angular 2 community has been using awesome-typescript-loader. I hate to advocate a competing loader.... but ts-loader correctly transpiles const enums. The only way we could solve this crippling issue was simply to switch. |
Is it possiblle (how I can ) to change the typescript loader in angular-cli (beta 24)? |
Oh geeze... I think I may get in trouble if I start giving directions on how to setup ts-loader here... It is extremely simple though. They drop directly in and out from one another, as they are competing loaders. http://stackoverflow.com/ may have information that you need. I think once you attempt changing it out, you will find it was surprisingly simple. |
I think, I found a solution. Example:
MyComponent.component.ts
This works with angular-cli beta 24. |
Interesting. I am glad you found something that works for you in the meantime. Although this does not solve the most crippling aspect of the bug, in that all const enum in any @type you include will not transpile correctly. Since "d.ts" files are the fundamental unit of how typing works in typescript, this is a big problem being that any "npm install @type" will not allow you to use the const enum in their definitions, and may even break the 3rd party library that you include. You really shouldn't try to hack your way around something like this. It is a far better idea to just use a correctly implemented compiler. |
@ZenSoftware all you say is absolutely correct. I migrate now a project from angular2.rc2 to angular 2.3.1 + angualr-cli and for me it is show stopper when I cannot use enums. so I create multiple enums.ts files. |
any news here or solutions for this problem? |
It is blocking me as well. Any news ? |
There was a change in the behavior of const enum compilation between v0.16.2 and v0.18.0.
Before upgrading my const enum values were replaced with the actual value.
Now they keep the variable name, which results in me not being able to access them from external module.
I tried to change preserveConstEnums in tsconfig.json, but nothing helps.
For example:
Results in:
Previously result was:
The text was updated successfully, but these errors were encountered: