I'm migrating from jest v27 to v29 and encounter this error:
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
This error occurs when trying to compile using tsc
.
Related packages in my 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"
}
Versions:
v16.15.1
v8.11.0
The problem here is that tsc is also building your tests file which is not ideal.
Exclude the test file from your tsconfig.json like I did below.
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"lib": [
"es2015"
],
"moduleResolution": "node",
"sourceMap": true,
"outDir": "bin",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
},
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
"include": [
"src/**/*"
],
"exclude": [
"src/**/*.spec.ts",
"src/**/*.test.ts"
]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.