typescript - @types/jest index.d.ts 文件返回错误

标签 typescript npm jestjs stenciljs

我刚刚将 @types/jest npm 安装到我的 stenciljs 入门应用程序,现在,当我开始我的项目时,新安装的节点包返回了几个错误。以下是当我转到 npm start 我的项目时它返回的错误:

[ ERROR ]  TypeScript: node_modules/@types/jest/index.d.ts:39:30
           A rest parameter must be of an array type.

     L39:  type ArgsType<T> = T extends (...args: infer A) => any ? A : never;

[ ERROR ]  TypeScript: node_modules/@types/jest/index.d.ts:218:112
           A tuple type element list cannot be empty.

    L217:   */
    L218:  ction spyOn<T extends {}, M extends keyof T>(object: T, method: M, accessType: 'get'): SpyInstance<T[M], []>;
    L219:  function spyOn<T extends {}, M extends keyof T>(object: T, method: M, accessType: 'set'): SpyInstance<void, [T[M]]>;

[ ERROR ]  TypeScript: node_modules/@types/jest/index.d.ts:220:144
           Type 'ArgsType<T[M]>' does not satisfy the constraint 'any[]'. Type
           '{}' is not assignable to type 'any[]'. Property 'length' is missing
           in type '{}'.

    L219:  function spyOn<T extends {}, M extends keyof T>(object: T, method: M, accessType: 'set'): SpyInstance<void, [T[M]]>;
    L220:   T, method: M): T[M] extends (...args: any[]) => any ? SpyInstance<ReturnType<T[M]>, ArgsType<T[M]>> : never;
    L221:  /**

[ ERROR ]  TypeScript: node_modules/@types/jest/index.d.ts:807:50
           Type 'ArgsType<T[P]>' does not satisfy the constraint 'any[]'. Type
           '{}' is not assignable to type 'any[]'.

    L806:  type Mocked<T> = {
    L807:      [P in keyof T]: T[P] & MockInstance<T[P], ArgsType<T[P]>>;
    L808:  } & T;

这是我的 package.json:

...
  "dependencies": {
    "@stencil/core": "~0.15.2",
    "@stencil/router": "~0.3.1",
    "imask": "^4.1.5",
    "jwt-decode": "^2.2.0",
    "material-design-icons": "^3.0.1"
  },
  "license": "MIT",
  "devDependencies": {
    "@types/jest": "^23.3.14",
    "@types/puppeteer": "1.12.1",
    "jest": "23.6.0",
    "jest-cli": "23.6.0",
    "puppeteer": "1.8.0",
    "workbox-build": "3.4.1"
  }
...

这是我的 tsconfig.json:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "allowUnreachableCode": false,
    "declaration": false,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "moduleResolution": "node",
    "module": "esnext",
    "target": "es2017",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "jsx": "react",
    "jsxFactory": "h"
  },
  "include": [
    "src"
  ],
  "exclude": [
    "node_modules"
  ]
}

我已尝试使用新的模板启动应用程序复制错误,但它不是应用程序。此外,尝试删除我的 package-lock.json 并重新安装包以消除任何潜在的冲突。

最佳答案

尝试将 "skipLibCheck": true 添加到 tsconfig.json 以跳过所有声明 (.d.ts) 文件的类型检查。

编辑:这更像是一个“大锤”解决方法,而不是实际修复。正如另一个答案中所提到的,这个问题的发生可能是因为 Jest 类型是为比项目中使用的版本更新的 TypeScript 版本制作的。因此,正确的解决方法是将项目升级到更新的 TS 版本。

关于typescript - @types/jest index.d.ts 文件返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54639274/

相关文章:

typescript - 如何使用 Typescript 3.2.2 进行命令行编译?

javascript - 类型 'isvalid' 上不存在属性 'KnockoutObservable'

angularjs - 如何将 qrcode-generator 导入 angular 2 应用程序?

typescript - 在 npm 的 typescript 中打包环境模块的正确方法

javascript - Jest v22.0.6 始终将 process.env 数组转换为字符串

javascript - Jest 配置

javascript - 在接口(interface) Typescript 中定义回调

http - 代理后面的 npm 失败,状态为 403

javascript - npm 安装 + 额外命令

unit-testing - 如何通过 JEST 检测模拟依赖库中的调用?