angular / tsickle

Tsickle — TypeScript to Closure Translator
MIT License
896 stars 110 forks source link

Does tsickle handle get/set accessors? #1462

Closed simonsarris closed 1 year ago

simonsarris commented 1 year ago

Sorry I know that this is not a bug report per se, but looking for a clarification of tsickle's limitations.

I am hoping to use tsickle with a .d.ts input to create closure externs. With a simple example like:

// .d.ts input for tsickle
declare class Class1 {
  constructor(init?: any);
  get test(): 'default' | 'a' | 'b';
  set test(value: 'default' | 'a' | 'b');
  static isBlah(): boolean;
}

The ouput contains "TODO: GetAccessor" for the properties:

/**
 * @constructor
 * @struct
 * @public
 * @param {?=} init
 */
function Class1(init) {}

/* TODO: GetAccessor: test */

/* TODO: SetAccessor: test */

/**
 * @public
 * @return {boolean}
 */
Class1.isBlah = function() {};

Is this an intentional limitation of tsickle? Or is there an expected syntax for accessors? Or something else I'm doing quite wrong?

frigus02 commented 1 year ago

Sorry for the slow response. I overlooked this issue in the last days.

Accessor support was added in https://github.com/angular/tsickle/commit/d65bd3ee85ce3f7a705c755f7b7011a1ff6e4ab8.

We haven't had a tsickle release since then, mostly because we consider tsickle unsupported. Tsickle is only useful with Closure Compiler and unless you have specific use cases you're probably better off with one of the newer minifiers out there.

simonsarris commented 1 year ago

I see. I am using the Closure Compiler - in fact I've been using the Closure Compiler since about 2011, maybe 2012, to compile a library (GoJS). When we moved to TypeScript I originally looked at tsickle but rejected it, and instead wrote my own convoluted script to massage the TS output to work in the CC. This has been fine for years.

However, Closure Compiler recently deprecated the @expose flag, which I was making heavy use of, so I figured I should make real externs, hence renewed interest in how tsickle is doing it.

Thank you for replying. I suppose I should close this.

frigus02 commented 1 year ago

Yeah, I'm sorry about that. I would recommend you try one of the newer minifiers (terser, esbuild, swc) and see if you can get similar results from them. We found these optimize most open source libraries really well and are much faster than Closure Compiler.

simonsarris commented 1 year ago

The closure Compiler is a beautiful piece of software, and the size gains are really good (though people don't care as much about bundle size a decade later), so I hope to keep using it. But I may need to roll my own externs-maker. Thanks for you explanations.