我的测试代码如下:
function test(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) {
return descriptor;
}
class Test {
@test
hello() {
}
}
但是编译器报错
Error:(33, 5) TS1241: Unable to resolve signature of method decorator when called as an expression.
Supplied parameters do not match any signature of call target.
我已经指定: --experimentalDecorators --emitDecoratorMetadata
最佳答案
似乎 TypeScript 期望装饰器函数的返回类型为“any”或“void”。因此,在下面的示例中,如果我们将 : any
添加到末尾,它就会正常工作。
function test(target: Object,
propertyKey: string,
descriptor: TypedPropertyDescriptor<any>): any {
return descriptor;
}
关于 typescript TS1241 : Unable to resolve signature of method decorator when called as an expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37694322/