这个问题似乎与Typescript的版本有关,尝试将Typescript版本降至4.2.4以下,可以解决问题。如果还是有问题,可以尝试加入“experimentalDecorators”选项到tsconfig.json文件中,如下:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"experimentalDecorators":true
}
}
如果还是有问题,可以考虑改变装饰器的实现方式,例如使用闭包:
function myDecorator(param: any) {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
// ...
};
}