我正在尝试使用 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, ...)
我错过了什么?
在不知道你的文件和文件夹结构的情况下很难判断,但存在错误意味着没有考虑到
experimentalDecorators
,我高度怀疑这是因为你的 TypeScript 文件位置与你在 include
中配置的 glob 模式不匹配财产。