我有一个Angular项目。
由于某种原因,我的一个测试实用程序似乎被编译成dev / prod版本,并产生了error TS2304: Cannot find name 'expect'
。基于IDE引用,它仅在*.mock.ts
和*.stub.ts
文件中使用。
我能够在一个级别上跟踪进口,但后来迷路了...
我的查找方法是查看所有导出的函数并查看它们的引用。我以这种方式找到了3个文件。我将expect()
放在其中的每一个上,进行重建,并且其中一个发生了错误。因此,我重复了该过程以发现
树:
flushController.ts (error)
|- resize-observer.stub.ts (no error)
|- apis.service.stub.ts (no error)
|- image.mock.ts (error when `expect()` was added)
||- slidesho.directive.spec.ts (no error)
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"strict": true,
"strictFunctionTypes": true,
"lib": [
"esnext",
"dom"
]
}
}
tsconfig.app.json
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/app",
"types": [],
},
"exclude": [
"test.ts",
"test-util",
"**/*.mock.ts",
"**/*.spec.ts",
],
}
tsconfig.spec.json
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": [
"jasmine",
"node"
],
"strictNullChecks": false
},
"files": [
"src/test.ts",
"src/polyfills.ts"
],
"include": [
"**/*.spec.ts",
"**/*.mock.ts",
"**/*.stub.ts",
"**/test-util/*.ts",
"**/*.d.ts"
]
}
如何消除该错误?
如何跟踪错误的来源,谁导入了该文件?