2016-02-28 49 views
2

我想在使用Visual Studio Code for Mac的Typescript中設置Angular 2中的組件。當我使用下面的代碼,我得到這些錯誤:duplicate identifier 'Component'.Duplicate identifier' DashboardComponent'.在Visual Studio代碼中有重複的標識符錯誤w/Angular 2 Typescript

import {Component} from 'angular2/core'; 

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

export class DashboardComponent { 

} 

我的文件結構如下:

app 
-dashboard 
--dashboard.component.html 
--dashboard.component.ts 
-app.component.html 
-app.component.ts 
-main.ts 
index.html 

我不是在代碼中導出類DashboardComponent其他地方。

我不確定這是Visual Studio代碼問題還是Typescript/Angular2問題。任何想法我在這裏做錯了嗎?

+1

粘貼您的tsconfig.json文件。 –

回答

7

此類問題的常見原因是,您確實在項目中多次導出該標識符(即項目根目錄下的所有內容),d.ts文件中的某處深度嵌套在文件夾結構中。爲了消除這種錯誤,通常的路線是排除'node_modules'和(如果你使用類型)'browser'或'main'typings文件夾,只留下一個。這是通過使用tsconfig.json的「排除」部分完成的。話雖如此,典型的TSCONF將看起來像這樣:

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

希望這可以幫助。

相關問題