我正在尝试在类中未包含的函数中添加自定义 TypeScript 装饰器,似乎无论我做什么,编译器都在提示。
有什么想法吗?可能吗?
最佳答案
add a custom TypeScript decorator in a function
不是原始函数。主要问题是处理函数的提升
。任何将一个函数包装在另一个函数中的尝试都会破坏提升。
支持目标
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.
文档:https://www.typescriptlang.org/docs/handbook/decorators.html#decorators
关于功能的 Typescript 装饰器,而不是方法。可能的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37518913/