Angular Typescript - exclude在tsconfig.json中不起作用

时间:2018-05-29 16:13:56

标签: angular typescript npm tsconfig

目前我遇到了node_modules中的一个模块的问题,而r编译Angular 4项目并得到如下错误,因此我决定在tsconfig.json中排除这个项目,但我仍然得到错误,Can有人帮助我

ERROR in D:/workspace/demo/node_modules/@types/d3-collection/index.d.ts (148,23): ',' expected.

ERROR in D:/workspace/demo/node_modules/@types/d3-collection/index.d.ts (483,40): ',' expected.

ERROR in D:/workspace/demo/node_modules/@types/d3-collection/index.d.ts (148,25): Type parameter name cannot be 'any'

因此我决定排除node_modules以避免这些错误,但在运行npm start

时我仍面临同样的错误

tsconfig.json

{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es6",
      "dom"
    ],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  },
  "exclude": [
    "**/node_modules/*"
  ]
}

1 个答案:

答案 0 :(得分:13)

你应该添加skipLibCheck它会跳过所有声明文件的类型检查(* .d.ts)。

https://www.typescriptlang.org/docs/handbook/compiler-options.html

{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es6",
      "dom"
    ],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es5",
    "skipLibCheck": true,
    "types": ["d3-collection"]
  },
  "exclude": [
    "node_modules"
  ]
}