本文介绍了Angular Typescript-排除在tsconfig.json中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Currently I am facing issue with one of the modules inside node_modules while r compiling the Angular 4 Project and the getting the error as below hence I decided to exclude this project in the tsconfig.json but still I am getting the error, Can someone help me here

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

Hence I decided to exclude the node_modules to avoid these errors but still I am facing the same error when running 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)的类型检查.

you should add skipLibCheck it skips type checking of all declaration files (*.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"
  ]
}

这篇关于Angular Typescript-排除在tsconfig.json中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 08:34