功能的 Typescript 装饰器,而不是方法。可能的?

标签 typescript decorator

我正在尝试在类中未包含的函数中添加自定义 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, 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

关于功能的 Typescript 装饰器,而不是方法。可能的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37518913/

相关文章:

javascript - Angular中的图像放大镜

javascript - Angular 2+ 如何在打开模态时将焦点集中到模态输入?

typescript TS7053 : Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'

python - 在 django 中装饰模型类并在装饰器中保存

ruby - 是否可以验证 Draper 装饰器中的上下文?

javascript - 如何实现 es5 样式 "class"的 Typescript 接口(interface)?

Python装饰器函数调用深度,结构化输出

Python装饰器跳过被装饰函数的代码

design-patterns - 策略模式 VS 装饰模式

javascript - 类型 'entries' 上不存在属性 'ObjectConstructor'