Angular 9升级在编译期间导致@types错误

时间:2020-06-03 15:39:56

标签: angular angular9

按照官方的角度指南进行升级后,最近将我的项目从7号角升级到9号角。尝试ng serve应用程序时出现很多@types错误。

ERROR in node_modules/@types/jasmine/index.d.ts:16:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: beforeAll, beforeEach, afterAll, afterEach, describe, fdescribe, xdescribe, it, fit, xit, expect, clock, DEFAULT_TIMEOUT_INTERVAL, CustomMatcherFactory, CustomEqualityTester

16 type ImplementationCallback = (() => Promise<any>) | ((done: DoneFn) => void);
   ~~~~

  node_modules/@types/jest/index.d.ts:34:1
    34 declare var beforeAll: jest.Lifecycle;
       ~~~~~~~
    Conflicts are in this file.
node_modules/@types/jasmine/index.d.ts:190:15 - error TS2428: All declarations of 'ArrayContaining' must have identical type parameters.

190     interface ArrayContaining<T> {
                  ~~~~~~~~~~~~~~~
node_modules/@types/jasmine/index.d.ts:197:15 - error TS2428: All declarations of 'ObjectContaining' must have identical type parameters.

197     interface ObjectContaining<T> {
                  ~~~~~~~~~~~~~~~~
node_modules/@types/jasmine/index.d.ts:245:9 - error TS2687: All declarations of 'message' must have identical modifiers.

245         message?: string;
            ~~~~~~~
node_modules/@types/jest/index.d.ts:34:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: beforeAll, beforeEach, afterAll, afterEach, describe, fdescribe, xdescribe, it, fit, xit, expect, clock, DEFAULT_TIMEOUT_INTERVAL, CustomMatcherFactory, CustomEqualityTester

34 declare var beforeAll: jest.Lifecycle;
   ~~~~~~~

  node_modules/@types/jasmine/index.d.ts:16:1
    16 type ImplementationCallback = (() => Promise<any>) | ((done: DoneFn) => void);
       ~~~~
    Conflicts are in this file.
node_modules/@types/jest/index.d.ts:1331:46 - error TS2314: Generic type 'ArrayContaining<T>' requires 1 type argument(s).

1331     function arrayContaining(sample: any[]): ArrayContaining;
                                                  ~~~~~~~~~~~~~~~
node_modules/@types/jest/index.d.ts:1332:45 - error TS2314: Generic type 'ObjectContaining<T>' requires 1 type argument(s).

1332     function objectContaining(sample: any): ObjectContaining;
                                                 ~~~~~~~~~~~~~~~~
node_modules/@types/jest/index.d.ts:1358:15 - error TS2428: All declarations of 'ArrayContaining' must have identical type parameters.

1358     interface ArrayContaining {
                   ~~~~~~~~~~~~~~~
node_modules/@types/jest/index.d.ts:1364:15 - error TS2428: All declarations of 'ObjectContaining' must have identical type parameters.

1364     interface ObjectContaining {
                   ~~~~~~~~~~~~~~~~
node_modules/@types/jest/index.d.ts:1472:9 - error TS2374: Duplicate string index signature.

1472         [index: string]: CustomMatcherFactory;
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@types/jest/index.d.ts:1492:9 - error TS2687: All declarations of 'message' must have identical modifiers.

1492         message: string | (() => string);
             ~~~~~~~
node_modules/@types/jest/index.d.ts:1492:9 - error TS2717: Subsequent property declarations must have the same type.  Property 'message' must be of type 'string', but here has type 'string | (() => string)'.

1492         message: string | (() => string);
             ~~~~~~~

  node_modules/@types/jasmine/index.d.ts:245:9
    245         message?: string;
                ~~~~~~~
    'message' was also declared here.
node_modules/@types/jest/index.d.ts:1497:9 - error TS2375: Duplicate number index signature.

1497         [n: number]: T;
             ~~~~~~~~~~~~~~~
node_modules/@types/node/assert.d.ts:56:14 - error TS2300: Duplicate identifier 'assert'.

56     export = assert;
                ~~~~~~

  node_modules/@types/node/ts3.7/assert.d.ts:56:14
    56     export = assert;
                    ~~~~~~
    'assert' was also declared here.
node_modules/@types/node/globals.global.d.ts:1:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'global' must be of type 'Global & typeof globalThis', but here has type 'Global'.

1 declare var global: NodeJS.Global;
              ~~~~~~

  node_modules/@types/node/ts3.5/globals.global.d.ts:1:13
    1 declare var global: NodeJS.Global & typeof globalThis;
                  ~~~~~~
    'global' was also declared here.
node_modules/@types/node/ts3.7/assert.d.ts:56:14 - error TS2300: Duplicate identifier 'assert'.

56     export = assert;
                ~~~~~~

  node_modules/@types/node/assert.d.ts:56:14
    56     export = assert;
                    ~~~~~~
    'assert' was also declared here.

这是我的tsconfig
tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "esnext",
      "dom"
    ],
    "module": "esnext"
  },
  "include": [
    "src/**/*.ts",
    "node_modules/@types",
    "node_modules/uicomponents/**/*.ts",
    "node_modules/mfa-ui/**/*.ts",
    "node_modules/inbox-notification/**/*.ts"
  ]
}

package.json 中,我具有以下相关的开发依赖项

    "@types/chai": "^4.1.7",
    "@types/chai-as-promised": "^7.1.0",
    "@types/cucumber": "^4.0.4",
    "@types/express": "^4.0.39",
    "@types/fs-extra": "4.0.3",
    "@types/google-maps": "^3.2.0",
    "@types/jasmine": "^2.8.8",
    "@types/jasminewd2": "2.0.6",
    "@types/jquery": "^3.3.33",
    "@types/klaw-sync": "1.1.0",
    "@types/lodash": "^4.14.149",
    "@types/node": "^13.13.0",
    "@types/node-fetch": "^1.6.7",
    "@types/jest": "^25.1.3",
    "typescript": "3.8.3",

我尝试过的事情
删除node_modules,package-lock.json并多次运行npm cache verify。 删除src下所有与应用相关的代码,以测试其是否编译成功。 还尝试在tsconfig中使用显式类型,但不适用于我。

"compilerOptions": {
    "types" : ["node"]
 }

任何建议将不胜感激。

0 个答案:

没有答案