我在 TypeScript 中有两个模块:
module superModule {
export interface myInterface { /*...*/ }
}
module app.superModule {
var x: superModule.myInterface;
}
请注意,有两个不同的“superModule”模块。第一个位于根目录,第二个作为应用程序模块的子模块。
上面的代码被评估为缺少“myInterface”接口(interface),因为编译器仅在 app.superModule 中搜索。
如何从子模块 superModule 访问“root”superModule?
TypeScript Playground :http://goo.gl/BdOJ1D
最佳答案
TypeScript 中没有“global”关键字或等效关键字,但您可以使用 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;
}
关于typescript - 访问 "root"模块与实际子模块同名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20653984/