在打字稿中使用 tsyringe 装饰器时出错

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

我正在尝试使用 tsyringe typescript 库,但甚至无法添加任何装饰器,因为 VsCode 抱怨它们。

我正在使用打字稿5。

这是

tsconfig.json
- 它具有由
tsyringe
文档记录的所需
experimentalDecorators
emitDecoratorMetadata

{
   "compilerOptions": {
      "baseUrl": "src/",
      "declaration": true,
      "declarationDir": "build/",
      "emitDeclarationOnly": true,
      "esModuleInterop": true,
      "target": "ESNext",
      "useDefineForClassFields": true,
      "module": "ESNext",
      "lib": [
         "ESNext",
         "DOM",
         "DOM.Iterable",
         "ES2021.String"
      ],
      "moduleResolution": "Node",
      "strict": true,
      "resolveJsonModule": true,
      "isolatedModules": true,
      "noUnusedLocals": false,
      "noUnusedParameters": false,
      "noImplicitReturns": true,
      "skipLibCheck": true,
      "typeRoots": [
         "node_modules/@types"
      ],
      "experimentalDecorators": true,
      "emitDecoratorMetadata": true
   },
   "include": [
      "./src/*", "@types"
   ],
   "exclude": [
      "./src/tests/**"
   ]
}

错误

作为表达式调用时无法解析类装饰器的签名

@injectable()
export class WorkerRuntime implements Runtime { ... }

装饰器在这里无效

constructor(@inject("pageMonitor") private pageAwaiter: Awaiter, ...)

我错过了什么?

typescript visual-studio-code dependency-injection typescript-decorator tsyringe
1个回答
0
投票

在不知道你的文件和文件夹结构的情况下很难判断,但存在错误意味着没有考虑到

experimentalDecorators
,我高度怀疑这是因为你的 TypeScript 文件位置与你在
include
中配置的 glob 模式不匹配财产。

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