-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closure Compiler incompatible with TypeScript method decorators #2065
Comments
Can you provide more detail on how Closure Compiler failed on the TypeScript output? |
Sorry, should've provided this initially. The issue here is that Closure Compiler renamed my |
Closure-compiler can rename string references safely now with __decorate([
resub_1.autoSubscribe
], AuthStoreImpl.prototype,
goog.reflect.objectProperty("getUser", AuthStoreImpl.prototype),
null); That should safely compile. edit: assuming I inferred the types correctly that is |
@mprobst probably knows of a good way to handle this. |
@evmar is the expert. We're maintaining a tool called tsickle (http://github.com/angular/tsickle) that rewrites TypeScript output to be Closure compatible (including type annotations, actually). I'm not sure if we have something to fix this renaming issue with method decorators specifically, but it shouldn't be too hard to fix, I guess? Alternatively, you could also ask the MS folks to change their emit to avoid quoting the method, e.g. AuthStoreImpl.prototype.getUser = __decorate([
resub_1.autoSubscribe
], AuthStoreImpl.prototype.getUser, null); |
I would love if the decorator didn't use strings, and I'll likely also reach out to the TS team as well. As for using |
@btraut please do file an issue against tsickle. Depending on the response from MS, this is something we should do. |
Posted over on the TS issues as well: |
@btraut One option available to you out of the box is to write a custom |
Sounds like the function name, "getUser" in my case eventually gets passed into |
@rbuckton the problem is that |
Ah, I see. |
I'm going to close this issue as it doesn't appear to be anything the compiler itself can handle. |
Thanks for the help, @ChadKillingsworth. |
It appears that the use of method decorators from TypeScript fall flat on their face when run through Closure Compiler due to the use of function names being passed as strings.
I have an
AuthStoreImpl
class that declares agetUser
method that has an@autoSubscribe
decorator. TypeScript compiles this by adding this after the class definition:Obviously I can use
@nocompile
to prevent any file that uses a decorator to remain untouched, but that kind of defeats the purpose. What I would really love to do is to add an annotation to thegetUser
method to prevent renaming of just that method, but I was disappointed to read that there's no plans to allow this granularity.If I may ask, what's the reason behind the decision to not allow inline annotations on specific symbols? It seems this would empower users to work around a lot of issues with Closure Compiler being to aggressive, especially when those users don't have complete control over their code (as is the case with code compiled by TypeScript).
The text was updated successfully, but these errors were encountered: