gcanti / io-ts-codegen

Code generation for io-ts
https://gcanti.github.io/io-ts-codegen/
MIT License
155 stars 14 forks source link

Generate externs for google closure compiler #35

Open mk0x9 opened 5 years ago

mk0x9 commented 5 years ago

Google closure compiler mangles all the property names unless you either use bracket syntax to access property (foo['bar'] instead of foo.bar) or specify extern file with external declarations (works similar to ambient declarations in typescript).

Would be extremely nice to be able to generate extern definitions for closure compiler!

mk0x9 commented 5 years ago

I think I can do it. The only things I yet noted that JSDoc doesn't support intersection types (just enumerate all possible properties and their types) and literal values (just use possible types of that values).

https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System

mk0x9 commented 5 years ago

I did basic stuff (https://github.com/mk0x9/io-ts-codegen/commit/f720056209dfe76cae1aa380224dacbfdb392582), but merging type definitions with same properties would take some time later.

gcanti commented 5 years ago

@mk0x9 not sure what's the problem here (I'm not acquainted with GCC) but I think that you can disable renaming https://github.com/google/closure-compiler/pull/2707 is this related?

mk0x9 commented 5 years ago

It kinda defeats purpose of ADVANCED optimizations. I'll attach examples later, probably at the evening, showing what it is and why I'm doing this.

mk0x9 commented 5 years ago

Here you can find brief description about GCC's advanced optimizations: https://developers.google.com/closure/compiler/docs/compilation_levels#advanced_optimizations

And here is useful introduction to GCC: https://github.com/roman01la/closure-compiler-handbook