为什么我得到这个和更多类似的错误?我正在添加一个链接到回购以及下面的关键代码片段。我认为我对依赖和“包括”链接的工作方式有一个基本的误解。

csvproc(master)> tsc
node_modules/typescript/bin/lib.core.d.ts(83,5): error TS2300: Duplicate identifier 'configurable'.
node_modules/typescript/bin/lib.core.d.ts(84,5): error TS2300: Duplicate identifier 'enumerable'.
node_modules/typescript/bin/lib.core.d.ts(85,5): error TS2300: Duplicate identifier 'value'.
node_modules/typescript/bin/lib.core.d.ts(86,5): error TS2300: Duplicate identifier 'writable'.

所有代码都可以在这里找到。

我的tsconfig.json:

{
    "compilerOptions": {
        "module": "commonjs",
        "noImplicitAny": false,
        "outDir": "built/",
        "sourceMap": true,
        "target": "es5"
    }
}

我的tsd.json:

{
  "version": "v4",
  "repo": "borisyankov/DefinitelyTyped",
  "ref": "master",
  "path": "typings",
  "bundle": "typings/tsd.d.ts",
  "installed": {
    "node/node-0.10.d.ts": {
      "commit": "6387999eb899d0ba02d37dd8697647718caca230"
    },
    "should/should.d.ts": {
      "commit": "e1182d56ccb192379eade6055d9ba3fb6a0bacc4"
    }
  }
}

我的tsd.d.ts:

{
  "version": "v4",
  "repo": "borisyankov/DefinitelyTyped",
  "ref": "master",
  "path": "typings",
  "bundle": "typings/tsd.d.ts",
  "installed": {
    "node/node-0.10.d.ts": {
      "commit": "6387999eb899d0ba02d37dd8697647718caca230"
    },
    "should/should.d.ts": {
      "commit": "e1182d56ccb192379eade6055d9ba3fb6a0bacc4"
    }
  }
}

当前回答

在tsconfig中启用skipLibCheck为我修复了它。

{
  "compilerOptions": {
    "skipLibCheck": true /* Skip type checking all .d.ts files. */
  },
  "exclude": ["node_modules"],
  "include": ["./src/**/*.ts"]
}

其他回答

简单地解决问题:

删除“node_modules”文件夹 运行npm install获取所有版本正确的包

在我的例子中,问题发生在更改Git分支之后,其中一个新分支使用了一组不同的节点模块。旧分支使用的是TypeScript v1.8,新分支使用的是TypeScript v2.0

使用webpack时,我遇到了同样的错误,只是以防排除。d。Ts文件在您的tsconfig。Json和node_modules解决了我的问题:

"exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts",
    "typings/index.d.ts"
] 

更新:typeings的1.0版本改变了输出结构,下面的答案涉及1.0之前的版本。

如果您正在使用tsconfig中的Typings和exclude。Json,你可能会遇到重复类型的问题,需要如下:

{
  "exclude": [
    "typings/browser.d.ts",
    "typings/browser",
    "node_modules"
  ]
}

为了简化与TypeScript的集成,有两个文件- types /main.d。t和类型/浏览器。d。生成t -引用项目中安装的所有类型,每次只能使用其中一个类型。

因此,根据您需要的版本,您应该排除(或包括)“浏览器”或“主”类型的文件,但不能同时排除(或包括)“浏览器”或“主”类型的文件,因为这是副本的来源。

这一期Typings将对此进行更多的讨论。

在更改tsconfig后,我遇到了这个错误和其他错误。Json到目标:“es2015”,和模块:“es2015”。

base (AngularJS2快速入门)使用/// <引用路径="../../ types /index.d. "Ts " />。ts文件。为了解决这个问题,我必须去掉这条线。

这个问题是由于磁盘上有一个意外的文件夹(jspm_packages,不再被使用),源代码控制没有跟踪(并且从我的IDE中隐藏)。这里面有一个重复的TypeScript安装,这导致了问题。

这是一种边缘情况,但在这里留下一个答案,以防其他人在寻找这个解。