ToddThomson / tsproject

Typescript minifier and modular typescript bundle optimizer for gulp (Ts Vinyl Adapter).
Other
57 stars 12 forks source link

Duplicate Identifier when multiple files reference the same class #101

Closed holotrek closed 7 years ago

holotrek commented 7 years ago

Please take a look at this project: https://github.com/holotrek/hello-world-npm-module/releases/tag/v0.2 Note: branched this release to https://github.com/holotrek/hello-world-npm-module/tree/tsproject while trying other approaches on master.

If you try building as is, you get many errors indicating "duplicate identifiers", such as: "Duplicate identifier 'HelloWorldService'."

If you move hello-all.service.ts from src to test (i.e. removing it from the build). It will work. I don't understand why just adding an additional reference to a class would cause that class to be added to the bundle twice. Unless I'm missing something, it's a very common use case to reference a class from more than one other class.

I also tried to follow the notice at issue https://github.com/ToddThomson/tsproject/issues/50 by removing the import statements and wrapping each class file with namespace HelloWorld { }, but when I do that, I get the duplicate identifier error even without the hello-all.service.

I'm really getting frustrated by how difficult it is to create a basic TypeScript NPM module (spent 3 days trying to get this basic Hello World example working), and I'd really appreciate some help with this.

My End Goal: To put it simply, however is best to do it, I just want to take some classes in multiple files in src and create a hello_world.js and hello_world.d.ts for consumption by another TypeScript app.

P.S. You can run just the bundle part of the build task by calling gulp build which doesn't require the global typescript install.

ToddThomson commented 7 years ago

@holotrek Please take a look at how tsproject itself is built. It is a NPM module. Typescript, although wonderful, is a bit tricky to setup and comes with a learning curve when dealing with references.

holotrek commented 7 years ago

@ToddThomson Thanks for your response. I've taken a look at the code for tsproject, and it seems one big difference between it and what I'm trying to do is that you have one "entry point", i.e. tsproject.src command. I'm trying to provide a library (i.e. Angular), so maybe tsproject is simply not the right tool to use. I'm looking into simpler options like manually creating a .d.ts file that exports from the ones created by tsc, which I am basing off of what I see in Angular. Thanks for looking into this.