Typescript decorator for function, not method. Possible?
add a custom TypeScript decorator in a function
Not to a raw function. The main issue is dealing with hoisting
of functions. Any attempt to wrap a function in another function breaks the hoist.
Support Targets
A Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter. Decorators use the form
@expression
, whereexpression
must evaluate to a function that will be called at runtime with information about the decorated declaration.
Docs: https://www.typescriptlang.org/docs/handbook/decorators.html#decorators
![Nick Tsitlakidis](https://i.stack.imgur.com/7TOpy.jpg?s=256&g=1)
Nick Tsitlakidis
I am a software engineer and spend most of my time working with agile and high level technologies. I am a great fan of object oriented design and its best practices (design patterns, unit testing, etc) and try to use them in the projects I'm involved. I'm usually working in web or mobile platforms.
Updated on June 26, 2022Comments
-
Nick Tsitlakidis about 2 years
I'm trying to add a custom TypeScript decorator in a function which is not included in a class and it seems that the compiler is complaining no matter what I do.
Any thoughts? Is it possible?