【发布时间】:2020-01-30 01:16:54
【问题描述】:
我正在尝试在 typescript 中测试装饰器,但是当我编译 ts 代码时出现错误
error TS1241: Unable to resolve signature of method decorator when called as an expression.
error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
我在 tsconfig.json 中有正确的装饰器配置
{
"compilerOptions": {
"target" : "ES5",
"experimentalDecorators" : true,
"emitDecoratorMetadata" : true
}
}
我已经尝试了在互联网上找到的所有方法来解决这个问题,但错误没有发生
tsc 版本 3.4.2
根据一篇帖子的问题是因为在调用装饰器时编译os ts代码,它是用少一个参数调用的
__decorate([
f()
], C.prototype, "ffolow");
使用装饰器的类是
class C {
@f()
ffolow() {
console.log("FF called")
}
}
【问题讨论】:
-
请按照How to Ask 一个好问题的指南中的说明提供minimal reproducible example。如果我不能重现你的问题,我就不可能解决它。
标签: typescript decorator