Closed kkozlowski89 closed 6 years ago
It seems there are no these enums of index.js file, but why?
Ok I have my enums on index.js file In gulpfile.js I set treeshake: false
but still I cannot use it I wanted.
Anyone can help me?
Does this happen only in Playground? Have you tried npm link
and testing in a clean angular project? Also, try building the library and running npm pack
inside dist, grab the tar.gz
and run npm i path/to/tar.gz
in your angular app, and see if you still got trouble.
I'd just like to isolate the problem to the playground, the build artifact, or the source code itself.
Yes I tried in clean angular project. I resolved this issue - I made some workaround.
Few words of explanation: I generated my ts files via typelite library (c# library) Ts code is correct but js generated during tsc compilation not.
Generated js was:
var crtenum;
(function (crtenum) {
/** @enum {number} */
var FirstEnum = {
Test1 : 400,
Test2 : 401
};
FirstEnum [FirstEnum .Test1] = "Test1";
FirstEnum [FirstEnum .Test2] = "Test2";
})(crtenum || (crtenum = {}));
But should be:
var crtenum;
(function (crtenum) {
/** @enum {number} */
crtenum.FirstEnum = {
Test1 : 400,
Test2 : 401
};
crtenum.FirstEnum [FirstEnum .Test1] = "Test1";
crtenum.FirstEnum [FirstEnum .Test2] = "Test2";
})(crtenum || (crtenum = {}));
And I generated this code also in c# and later in gulpfile I added step to insert this code to index.js in correct place.
Everything works but I spent a lot of hours doing it.
Thanks, issue can be close.
@kkozlowski89 — Thank you for sharing your findings 👍 @caroso1222 — Thank you for the follow-up 👍
Hi,
I have defined enums like that:
File: enum.generated.ts
so in other files I can use it like that:
I use this approach for few angular application and everything works correctly. But when I started doing my private npm package it doesn't work. When I started playground I got error messages like that: Cannot read property 'Test1' of undefined
I used it for example:
in my module I have ofcourse:
I tried also
Any ideas? Thanks a lot!