-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Usage of decorators in raw functions #44828
Comments
Related: #7318 In the end this depends on TC39, so you should take a suggestion there. Please also note that the current decorator support in TypeScript is based on an old and outdated proposal. The team made clear that they don't do any more work on decorator support until the proposal is finished. |
is a non-negotiable checkbox, I’m afraid. |
I was afraid that I should mark all tue boxes. But I was pretty sure that such feature would fall in this category. But it makes sense to at least wait for TC39 before having it in TS. Pity, but understandable. @andrewbranch You could close for comments as well to avoid people finding this issue and start another big thread. Thanks for fast reply also @MartinJohns :) |
This is my solution:
execution-time.decorator.ts
some-function.ts
Final usage in client code:index.ts
P. S.Of course this is not a raw function. But its interface, i mean its usage looks like usage of raw function. And if you want wrap it with decorators, you should go to its wrapped class and in it do it with origin static method. |
Suggestion
Decorators are a very useful feature when we have to encapsulate some behaviors and enhance our code with such.
But, a game changer for those decorators would be if we could use them in raw functions as well, not only in class based scenarios.
🔍 Search Terms
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
I would like to be able to decorate a raw/plain JS function with decorators. So I won't need to every time I need a decorator wrap my function inside a class to be able to use it.
📃 Motivating Example
Today, if you need to create a decorator, let's say to wrap a Lambda handler function, you would need to somehow wrap it into a class and initialize this class and expose the handler of it.
But, if you could have decorators directly in raw JS function it would be more smooth and less "boilerplate".
💻 Use Cases
For example:
But rather, in order to have something similar, you would need to have this code:
The text was updated successfully, but these errors were encountered: