It is technically possible to take the ES6 output generated by the tsc
command and directly feed it into Closure Compiler, as Closure is designed to accept JavaScript as input. This process is already being used in various instances, such as Angular applications that are compiled with Closure Compiler including the rxjs library distribution in the closure bundle. You can check out an example at https://github.com/angular/closure-demo
However, in practice, there are a few reasons why it might be beneficial to use a tool like tsickle to transform the JavaScript code before it is processed by Closure.
- Enums emit does not work with Closure (or rollup, as far as I understand)
- Closure has limitations with ES6, such as its lack of support for
export *
- tsickle can re-write this to export {each, visible, symbol}
- Including JSDoc annotations can help Closure better understand the structure of the code, leading to improved optimizations and reduced warning messages.
Our current plan involves breaking down tsickle into multiple TS 2.3 emit transforms so that we can clearly identify which transforms need to be enabled in the compiler.
Adding types is not mandatory. If you disable tsickle's typed mode, it will simply display {?}
for the types. However, if you intend to use TypeScript's output alongside closure JS code, it is beneficial for the closure type-checker to recognize the types.
If you are open to exploring a new build tool, tsickle will be integrated into the Bazel toolchain at some point in https://github.com/bazelbuild/rules_typescript. In the meantime, you can submit a feature request for Tsickle's main support for more command-line flags. (There may also be a fork of Tsickle maintained by Lucidchart?)