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



目前我在编译 Angular 4 项目时遇到node_modules内部模块之一的问题,并得到如下错误,因此我决定在 tsconfig.json 中排除这个项目,但仍然收到错误,有人可以在这里帮助我吗

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/*"
]
}

您应该添加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"
]
}