-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[Experiment] feat(7342): Decorators not allowed classes expressions #42198
Conversation
d3415db
to
d8e2c87
Compare
670285f
to
14cbb1a
Compare
Dear @a-tarasyuk, you made my day, I'm very gratitude to you. Using your branch I was able to finally generate declaration files for my project, which make heavy use of mixins + decorators (#44304) Of course it took few hours of code tweaking, because TS is currently fragmented into 2 languages, but finally it works. |
Btw, I noticed that I can't just use this branch in my project, directly from github, like:
The package is installed, and can be used, but it contains the outdated Shoudn't |
I'm not sure about the |
I have to use it, otherwise I can't generate declaration files. Regarding |
But may be you can consider running |
@DanielRosenwasser How often do you update |
We LKG on |
@DanielRosenwasser Is it possible to get the latest |
@canonic-epicure I've merged |
Thanks! I'll give it a try. |
Closed in favor of waiting for the stable spec. The branch will be available, however, I think doesn't make sense to continue updating it. Summary of this feature #44555 /cc @canonic-epicure |
@a-tarasyuk I'm very frustrated with the decision about this PR. Just curious - what about the emerging ES decorators spec? It will still not be possible to use them in the class expressions? What do you think? |
In any case, I'm very grateful to you for this PR, it allows me to generate the declaration files for my project. Wish there would be more contributors like you in TS world. I'll have to stick with this branch and I guess I'll be rebasing regularly. 😅 |
Ok, so both legacy and ES decorators needs to be applicable for class expressions. This means your PR is actually future proof, as decorators emit can be abstracted, but using decorators in class expressions will remain as is. |
@a-tarasyuk Looks like you know the TS compiler internals very well, perhaps you can check this StackOverflow question and provide some brief instructions how that can be done? Would be very much appreciated. Seems nobody knows how to do that. |
I'm glad the decorators specs is finally approved to move forward. I really dislike the new This addition would be nice, but the workaround for now is easy: create classes as statements instead. F.e.: someAPI(class { @dec method() {} })
return class extends Foo { @dec prop = 123 } becomes class NewClass { @dec method() {} }
someAPI(NewClass)
class result extends Foo { @dec prop = 123 }
return result |
Fixes #7342
This is an experimental PR that aims to allow using decorators in ClassExpression members. Transform idea was taken from Babel, not sure if this is an acceptable way for TypeScript.
Any feedbacks are welcome.
Babel - es5
TS - es5
Babel - esnext
TS - esnext