我从jest v27迁移到v29时遇到以下错误:
node_modules/@jest/environment/build/index.d.ts:329:26 - error TS2430: Interface 'JestImportMeta' incorrectly extends interface 'ImportMeta'.
The types returned by 'jest.createMockFromModule(...)' are incompatible between these types.
Type 'unknown' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'unknown'.
329 export declare interface JestImportMeta extends ImportMeta {
~~~~~~~~~~~~~~
Found 1 error in node_modules/@jest/environment/build/index.d.ts:329
尝试使用tsc
进行编译时会发生这个错误。
我的package.json中的相关包:
"devDependencies": {
"@types/jest": "^29.0.0",
"jest": "^29.0.0",
"jest-environment-node": "^29.0.0",
"nodemon": "^2.0.4",
"ts-jest": "^29.0.0"
}
版本:
- 节点Js
v16.15.1
- 每分钟
v8.11.0
2条答案
按热度按时间htzpubme1#
这里的问题是tsc也在构建你的测试文件,这并不理想。
溶液:
从tsconfig.json中排除测试文件,如下所示。
myss37ts2#
这是类型中的一个错误,已在jest v29.1.0和@types/jest v29.0.3 www.example.com中修复https://github.com/facebook/jest/issues/13199#issuecomment-1260897649