由于打字,TypeScript 编译错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35776470/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeScript compile error due to typings
提问by Herman Fransen
I'm using typescript 1.7.5, typings 0.6.9 and angular 2.0.0-beta.0.
我正在使用 typescript 1.7.5,typings 0.6.9 和 angular 2.0.0-beta.0。
How can I get rid of the typescript compile error messages Duplicate identifierdue to typings definition files?
Duplicate identifier由于打字定义文件,我怎样才能摆脱打字稿编译错误消息?
The Duplicate identifiererror occurs in the definition files of the following directories:
将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
What's the compiler doing in node_modules/angular2directory since I excluded it in tsconfig.json?
编译器在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"
]
}
They are gone if I change the excludepart of tsconfig.json:
如果我更改以下exclude部分,它们就会消失tsconfig.json:
"exclude": [
"node_modules",
"typings"
]
But then after adding the following I get again the same Duplicate identifiercompile errors:
但是在添加以下内容后,我再次得到相同的Duplicate identifier编译错误:
/// <reference path="../../typings/browser.d.ts" />
typings.json
打字.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"
}
}
采纳答案by rgvassar
As basarat alludes to, you can either change:
正如 basarat 所暗示的,您可以更改:
"moduleResolution": "node",
to
到
"moduleResolution": "classic",
Or you can simply delete all of the duplicate typings from the typings folder. What's happening is that it's automatically importing all of the typings from the the node_modules folder of every importyou do in your code. It's also importing the typings that are dependencies of the browser.d.tsfile.
或者您可以简单地从打字文件夹中删除所有重复的打字。发生的事情是它会自动从import您在代码中执行的每个操作的 node_modules 文件夹中导入所有类型。它还导入作为browser.d.ts文件依赖项的类型。
回答by fikkatra
For me, choosing either 'browser' or 'main' (depending on your application: front end or back end) and excluding the other one in tsconfig.jsonworked:
对我来说,选择“浏览器”或“主要”(取决于您的应用程序:前端或后端)并排除另一个tsconfig.json工作:
"exclude": [
"node_modules",
"wwwroot",
"typings/main",
"typings/main.d.ts"
]
回答by basarat
What's the compiler doing in node_modules/angular2 directory since I excluded it in tsconfig.json
编译器在 node_modules/angular2 目录中做了什么,因为我在 tsconfig.json 中排除了它
Its looking at npm modules becuase of "moduleResolution": "node",but onlythe files that are imported (without the exclude it would look at allthe files).
它查看 npm 模块,因为"moduleResolution": "node",但只查看导入的文件(没有排除它会查看所有文件)。

