我使用的是打字稿1.7.5,類型爲0.6.9和角度爲2.0.0-beta.0。由於打字造成的TypeScript編譯錯誤
由於類型定義文件,我該如何擺脫打字稿編譯錯誤信息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
什麼是編譯器node_modules/angular2
目錄做的,因爲我在tsconfig.json
排除在外呢?
I also posted this question on 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"
]
}
如果我改變的tsconfig.json
的exclude
一部分,他們都走了:
"exclude": [
"node_modules",
"typings"
]
但後來加入以下後,我再次得到相同的Duplicate identifier
編譯錯誤:
/// <reference path="../../typings/browser.d.ts" />
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"
}
}
設置「moduleResolution」:「經典「會提供其他錯誤,但由於未找到要導入的模塊。 我不知道「node_modules/angular2/typing」和「typings」目錄中有重複的類型。刪除重複類型解決了問題 –
這個問題解決了嗎?我遇到了同樣的問題。我已經參加了一個禮拜,沒有任何解決方案對我有幫助。 –
如果你有完全相同的問題,那麼問題是他已經安裝了Angular 2已經包含的一些類型。這會導致重複。解決方案是卸載重複項。 – rgvassar