theseanl / tscc

A collection of tools to seamlessly bundle, minify Typescript with Closure Compiler
MIT License
161 stars 11 forks source link

Using external library which contains typing #757

Closed karadnized closed 1 year ago

karadnized commented 1 year ago

I've been trying to use reflect-metadata but i'm unable to get compiled with ADVANCED compilation

tscc.spec.json

 "external": {
    "reflect-metadata": "Reflect"
  }`

main.ts import "reflect-metadata";

I see externs generated for the package but no source code generated.

theseanl commented 1 year ago

Hi, merely importing the package only assigns certain functions to the global namespace Reflect, and Closure Compiler sees no code that uses the newly defined functions, so it isn't a surprise that the output is empty.

Also, having an external module's global alias that is already declared somewhere in closure compiler's externs (like your choice of Reflect) causes externs generated by TSCC to collide with closure compiler's own. I'd say it's safe-ish, but the behavior on externs collision isn't documented anywhere.

I think you don't need to declare it in external key. If you have a reproduction steps with codes that make an essential use of the reflect-metadata package, I can take a look.

karadnized commented 1 year ago

@theseanl https://github.com/karadnized/tscc-test-reflect

theseanl commented 1 year ago

And what's the issue with that repo? Tscc compiles the output just fine, and the output has the same behavior as the source.

karadnized commented 1 year ago

@theseanl The library should add functions the Reflect global. Reflect.defineMetadata is not a native function. It will be added the library and that's what i don't see.

It's more like adding extra functions to Reflect by they aren't there :). If webpack example will help i can create one

theseanl commented 1 year ago

Well, a good virtue of every bug report is to provide an expected behavior and an actual behavior you are observing. It seems that you don't understand what external does.