Tìm kiếm trang web

node.js - Giao diện 'JestImportMeta' kế thừa sai giao diện 'ImportMeta'


Tôi đang di chuyển từ jest v27 sang v29 và gặp lỗi này:

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

Lỗi này xảy ra khi cố gắng biên dịch sử dụng tsc.

Các gói liên quan trong package.json của tôi:

"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"
}

Phiên bản :

  • NodeJs v16.15.1
  • npm v8.11.0

Câu trả lời #1

Trong trường hợp của tôi, tôi đã phải cập nhật tsconfig.json để có dòng này dưới đối tượng compilerOptions:

"types": ["node"]

Nó cần phải biết cách sử dụng các loại nút một cách cụ thể

Câu trả lời #2

Có vẻ như lỗi này có thể đã được đưa trở lại trong jest 29.4.x. Để giải quyết vấn đề này, tôi đã làm: yarn upgrade jest@~29.2.0 @types/jest@~29.2.0

Bài viết liên quan