由于打字,TypeScript编译错误

Her*_*sen 14 typing typescript

我使用的是typescript 1.7.5,类型为0.6.9,角度为2.0.0-beta.0.

如何解决Duplicate identifier由于打字定义文件而导致的打字稿编译错误消息?

Duplicate identifier错误发生在以下目录的定义文件中:

node_modules/angular2/typings/es6-shim/es6-shim.d.ts
node_modules/angular2/typings/jasmine/jasmine.d.ts
node_modules/angular2/typings/zone/zone.d.ts
typings/browser/ambient/es6-promise/es6-promise.d.ts
typings/browser/ambient/es6-shim/es6-shim.d.ts
typings/browser/ambient/jasmine/jasmine.d.ts
typings/browser/ambient/karma/karma.d.ts
typings/browser/ambient/zone.js/zone.js.d.ts
Run Code Online (Sandbox Code Playgroud)

编译器在node_modules/angular2目录中做了什么,因为我将其排除在外tsconfig.json

我也在GitHub上发布了这个问题

tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "module": "system",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
    },
    "exclude": [
        "node_modules",
        "typings/main",
        "typings/main.d.ts"
    ]
}
Run Code Online (Sandbox Code Playgroud)

如果我改变了exclude部分tsconfig.json:

"exclude": [
    "node_modules",
    "typings"
]
Run Code Online (Sandbox Code Playgroud)

但是在添加以下内容之后我又得到了相同的Duplicate identifier编译错误:

/// <reference path="../../typings/browser.d.ts" />
Run Code Online (Sandbox Code Playgroud)

typings.json

{
  "name": "example-mean-app-client",
  "dependencies": {},
  "devDependencies": {},
  "ambientDependencies": {
    "bootstrap": "github:DefinitelyTyped/DefinitelyTyped/bootstrap/bootstrap.d.ts#4de74cb527395c13ba20b438c3a7a419ad931f1c",
    "es6-promise": "github:DefinitelyTyped/DefinitelyTyped/es6-promise/es6-promise.d.ts#830e8ebd9ef137d039d5c7ede24a421f08595f83",
    "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#4de74cb527395c13ba20b438c3a7a419ad931f1c",
    "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#dd638012d63e069f2c99d06ef4dcc9616a943ee4",
    "karma": "github:DefinitelyTyped/DefinitelyTyped/karma/karma.d.ts#02dd2f323e1bcb8a823269f89e0909ec9e5e38b5",
    "karma-jasmine": "github:DefinitelyTyped/DefinitelyTyped/karma-jasmine/karma-jasmine.d.ts#661e01689612eeb784e931e4f5274d4ea5d588b7",
    "systemjs": "github:DefinitelyTyped/DefinitelyTyped/systemjs/systemjs.d.ts#83af898254689400de8fb6495c34119ae57ec3fe",
    "zone.js": "github:DefinitelyTyped/DefinitelyTyped/zone.js/zone.js.d.ts#9027703c0bd831319dcdf7f3169f7a468537f448"
  }
}
Run Code Online (Sandbox Code Playgroud)

rgv*_*sar 3

正如 basarat 提到的,您可以更改:

"moduleResolution": "node",
Run Code Online (Sandbox Code Playgroud)

"moduleResolution": "classic",
Run Code Online (Sandbox Code Playgroud)

或者,您可以简单地从打字文件夹中删除所有重复的打字。import发生的情况是,它会自动从您在代码中执行的每个操作的 node_modules 文件夹中导入所有类型。它还导入作为文件依赖项的类型browser.d.ts