我对参数装饰器有疑问

问题描述 投票:0回答:1

我想使用 TSyringe 在我的应用程序中实现 DI。所以,我使用接口,这就是为什么我必须应用参数装饰器来链接接口和类。但我有一个问题“装饰器在这里无效。ts(1206)”并且类的 @injectable() 工作没有问题。

public constructor(@inject("Controller") private _controller: Controller) { }

我使用谷歌,尝试找到问题的解决方案。 我将“experimentalDecorators”、“emitDecoratorMetadata”更改为 true 和“useDefineForClassFields”: false,但这对我没有帮助。

这是我的 tsconfig.json:

 { "compilerOptions": { "target": "ES2020", "useDefineForClassFields": false, } "experimentalDecorators": true,  "emitDecoratorMetadata": true  }

typescript frontend decorator
1个回答
0
投票

您的 tsconfig.json 似乎有问题。 experimentDecorators和emitDecoratorMetadata选项应该在compilerOptions内。以便正确应用。 这是更新后的 tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2020",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "useDefineForClassFields": false
  }
}

当这个答案解决您的问题时,我会很高兴。

© www.soinside.com 2019 - 2024. All rights reserved.