在C#中,可以在文件顶部使用using子句,这样就可以在该命名空间中使用类型,而无需明确指定完整的命名空间来引用这些类型.TypeScript是否提供了替代方案?
Chi*_*hic 13
在TypeScript中,最接近能够直接使用外部模块的是别名.如TypeScript手册中所示,它使用如下:
module Shapes {
    export module Polygons {
        export class Triangle { }
        export class Square { }
    }
}
import polygons = Shapes.Polygons;
var sq = new polygons.Square(); // Same as 'new Shapes.Polygons.Square()'
Run Code Online (Sandbox Code Playgroud)
这不会将接口放在模块的根作用域上,因为如果更新了多边形模块,这可能会引入命名冲突,并清楚地表明您正在引用外部的东西.
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           9454 次  |  
        
|   最近记录:  |