web-dev-qa-db-ja.com

@ types / jestindex.d.tsファイルがエラーを返す

@ types/jestをstenciljsスターターアプリにnpmでインストールしましたが、プロジェクトを開始すると、新しくインストールされたノードパッケージがいくつかのエラーを返します。プロジェクトの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を削除し、パッケージを再インストールして、潜在的な競合を取り除きました。

4
hawaiiansurfer

TypeScriptのバージョンを3.3.4000に更新することは私を助けました。

0
Yaroslav