3 ms·
Is there a way to migrate jsdoc-annotated JavaScript code over to TS, and is TS's minifier as good as Google's closure-compiler yet?
by tannhaeuser 7y ago
Is there a way to migrate jsdoc-annotated JavaScript code over to TS, and is TS's minifier as good as Google's closure-compiler yet?
- smt88 7y agoI don't know of prod-quality tools to migrate from jsdoc to TS. TS does have comment-level typing, so you can get the benefits without transpiling anything (similar to Flow). TS pointedly does not minify output. It does the opposite: try to generate code that a human might have written. It's very easy to incorporate TS into a Babel or Webpack build pipeline though, so you can use a purpose-built minifier of your choice.
- vbitz 7y agoVisual Studio Code has a "Code Fix" that can automatically copies JSDoc into TypeScript annotations. This can be done to an entire file at once. TypeScript does not come with a minifier. The code it produces is compatible with the target version of JavaScript (e.g. compile ES6 modules into CommonJS) but unminified.
- tannhaeuser 7y agoI see. closure-compiler's "advanced" mode takes advantage of jsdoc type info for minifying so I guess generic syntactical minification won't compress as much for the time being.
- evmar 7y agoWe (Google TS team) maintain a tool[1] that transforms TS types into jsdoc types for the purpose of feeding them into 'advanced' mode. We also (to answer the grandparent question) maintain a tool[2] that converts Closure-annotated TS into JS. (Why both ways? We transition JS->TS and check it in as the code the user works with, while we use the TS->JS one within the compiler at optimization time.) [1] https://github.com/angular/tsickle https://github.com/angular/tsickle [2] 'gents', in this repo https://github.com/angular/clutz https://github.com/angular/clutz
- HDevo 7y agoThe closest things I know of are Clutz and Gents, maintained here: https://github.com/angular/clutz https://github.com/angular/clutz. They work with Closure-annotated JS (with JSDoc) though; not sure if it fits your use case.
- bpicolo 7y agoThe Angular project has a package for translating TS -> Closure, which appears to be used at Google in some capacity. https://github.com/angular/tsickle https://github.com/angular/tsickle
- Nitramp 7y agoYes, we use that to use TS together with Closure for all our TS code at Google. It's a bit difficult to hook up though, and we haven't had the cycles to make the open source version user friendly, I'm afraid :-(
- bpicolo 7y agoIt would be really cool to see the user-friendly version (though that might lead to a rabbit hole on the Closure side, too). The Closure compiler remains awesome, just difficult to make use of successfully.
- evmar 7y agoYou might try out https://github.com/theseanl/tscc https://github.com/theseanl/tscc , which aims to do this.