带有Angular 2 Typescript的Visual Studio代码中的重复标识符错误

Ken*_*Ken 2 visual-studio typescript angular

我正在尝试使用Visual Studio Code for Mac在Types中使用Typescript设置一个组件.当我使用以下代码时,我得到这些错误:duplicate identifier 'Component'.Duplicate identifier' DashboardComponent'.

import {Component} from 'angular2/core';

@Component({
   selector: 'dashboard',
   templateUrl: './dashboard.component.html'
})

export class DashboardComponent {

}
Run Code Online (Sandbox Code Playgroud)

我的文件结构如下所示:

app
-dashboard
--dashboard.component.html
--dashboard.component.ts
-app.component.html
-app.component.ts
-main.ts
index.html
Run Code Online (Sandbox Code Playgroud)

我没有DashboardComponent在代码中的任何其他地方导出类.

我不确定这是Visual Studio Code问题还是Typescript/Angular2问题.知道我在这里做错了吗?

Ami*_*mid 7

这种问题的常见原因是你在项目中有多次导出该标识符(即项目根目录下的所有内容),d.ts文件中的某些地方深层嵌套在文件夹结构中.为了消除这种错误,通常的做法是排除'node_modules'和(如果你使用typings)'browser'或'main'typings文件夹只留下一个.这是通过使用tsconfig.json的"exclude"部分完成的.说过典型的tsconfig看起来像这样:

{ 
    "compilerOptions": { 
    },
    "exclude": [
        "node_modules",
        "dist",
        "typings/browser.d.ts",
        "typings/browser/**"
    ]
} 
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.