2013-12-18 22 views
2

我在打字稿兩個模塊:打字稿 - 獲得「根」模塊相同的名稱,實際子模塊

module superModule { 
    export interface myInterface { /*...*/ } 
} 

module app.superModule { 
    var x: superModule.myInterface; 
} 

注意,有兩個不同的「superModule」模塊。第二個作爲app模塊的子模塊。

上面的代碼被評估爲缺少「myInterface」接口,因此編譯器僅在app.superModule中進行搜索。

如何從子模塊superModule訪問「root」超級模塊?

打字稿遊樂場:http://goo.gl/BdOJ1D

回答

2

有在打字稿沒有「全局」的關鍵字或等效的,但你可以使用import創建一個類型或變量別名:

module superModule { 
    export interface myInterface { /*...*/ } 
} 

// Can be placed anywhere where the top definition 
// of 'superModule' is visible 
import superModule_myInterface = superModule.myInterface; 
module app.superModule { 
    var x: superModule_myInterface; 
}