我在配置Mocha以支持我的打字稿代码时遇到问题。我在项目根目录的global.d.ts
文件夹中的src
中定义了一些类型。
我运行mocha -r ts-node/register test/**/*.ts
时收到以下错误:
TSError: ⨯ Unable to compile TypeScript:
src/mediator/index.ts:5:28 - error TS2304: Cannot find name 'DomainEvent'.
5 [key: string]: (event: DomainEvent) => Promise<void>
~~~~~~~~~~~
src/mediator/index.ts:11:57 - error TS2304: Cannot find name 'DomainEvent'.
11 registerHandler(eventType: string, handler: (event: DomainEvent) => Promise<void>) {
~~~~~~~~~~~
src/mediator/index.ts:18:37 - error TS2304: Cannot find name 'IntegrationEvent'.
18 async publish(integrationEvent: IntegrationEvent) {
当我运行ts-node ./src/app.ts
时,应用运行良好。有人知道我在做什么错吗?
我的tsconfig(我怀疑问题与此有关):
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "es6",
"noImplicitAny": false,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"@mediator": ["src/mediator"],
"*": [
"node_modules/*"
]
},
"typeRoots": [
"./global"
]
},
"include": [
"**/*.ts"
]
}
答案 0 :(得分:0)
在global.d.ts
中加入您的tsconfig.json
:
{
"compilerOptions": {
},
"include": [
"./global.d.ts",
"./src/**/*.d.ts"
]
}