功能的 Typescript 装饰器,而不是方法。可能的?
Typescript decorator for function, not method. Possible?
我正在尝试在 class 中未包含的函数中添加自定义 TypeScript 装饰器,无论我做什么,编译器似乎都在抱怨。
有什么想法吗?可能吗?
add a custom TypeScript decorator in a function
不是原始函数。主要问题是处理 hoisting
个函数。任何将一个函数包装在另一个函数中的尝试都会破坏提升。
支持对象
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
, where expression
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
我正在尝试在 class 中未包含的函数中添加自定义 TypeScript 装饰器,无论我做什么,编译器似乎都在抱怨。
有什么想法吗?可能吗?
add a custom TypeScript decorator in a function
不是原始函数。主要问题是处理 hoisting
个函数。任何将一个函数包装在另一个函数中的尝试都会破坏提升。
支持对象
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