I am trying to compile an angular project with the new tsickle/closure chain. However, it seems to have to following errors on all enums:
src/path/to/YourEnumType.ts:1: ERROR - Exports must be a statement at the top-level of a module
My code is this:
export enum YourEnumType {
None = 0,
OneThing = 1,
OtherThing = 2
}
How could I deal with this problem?
The Typescript compiler generates from exported enums this:
As we can see, yes, this generated Javascript uses the
exports
from inside a function.Digging into the typescript compiler, trying to play with its generated output format, and so on, I've found no way to work around this. Despite that, this Typescript code would be much better if it would be compiled as we can see in this answer:
Unfortunately, typescript doesn't do this.
Similar digging in the google closure compiler show that there is no way to work around this without modifying the google closure source code.
Thus, considering this, and other major problems with enums in the whole typescript world, I think the only way out is to avoid using typescript enums.