Closure Compiler + Typescript
I realize I'm late to the party, but regarding the Closure library: There now is an active fork of an up-to-date version of the Closure library that has
- Typescript definition (.d.ts) files
- uses ES6 code instead of the custom goog.require, goog.define internally (so has no dependency on the Closure compiler)
Technically, you can take ES6 output from tsc
and pipe it immediately to Closure Compiler, as the latter is spec'ed to accept JS as input. We do this already in many places, eg. Angular apps compiled with closure compiler take the rxjs library distribution and include it in the closure bundle. See https://github.com/angular/closure-demo
In practice, we find a few reasons to use something like tsickle to transform the JS before Closure sees it.
- enums emit doesn't work in Closure (or rollup IIUC)
- Closure has some limitations with ES6, for example it currently doesn't support
export *
- tsickle re-writes that toexport {each, visible, symbol}
- adding JSDoc annotations helps closure understand the structure of the code which can improve optimizations and reduces the number of warnings it prints.
Our current plan is to decompose tsickle into multiple TS 2.3 emit transforms, then we can be more clear which transforms actually need to be enabled in the compiler.
Adding types is optional. If you turn off tsickle's typed mode, we'll just print {?}
for the types instead. However, if you ever want to use TypeScript's output from closure JS code, then you'll want the closure type-checker to know the types.
If you're game for a new build tool, we will build tsickle into the Bazel toolchain in https://github.com/bazelbuild/rules_typescript at some point. In the meantime you can file a feature request for Tsickle's main to support more of the command-line flags. (But I think Lucidchart already maintains a fork of Tsickle?)