模块名称冲突时如何从 typescript.d.ts 文件访问接口?

Posted

技术标签:

【中文标题】模块名称冲突时如何从 typescript.d.ts 文件访问接口?【英文标题】:How to access an interface from a typescript.d.ts file when the module names conflict? 【发布时间】:2014-01-10 14:12:58 【问题描述】:

如何从 esri.dijit 中访问 i1?

module dijit 
    interface i1 ;


module esri 
    module dijit 
        interface i2 
        interface i3 extends dijit.i2, dijit.i1 
    

见Playground example。

【问题讨论】:

【参考方案1】:

两件事。首先,您需要导出一个接口,以便在模块外使用它:

module dijit 
    export interface i1 ;

其次,如果您要在本地使用相同的名称,则全局名称 dijit 将被隐藏。所以你需要创建一个别名:

module dijit 
    export interface i1 ;

import alias = dijit;

现在你的完整代码:

module dijit 
    export interface i1 ;

import alias = dijit;

module esri    
    module dijit 
        export interface i2 
        interface i3 extends dijit.i2, alias.i1 
    

【讨论】:

以上是关于模块名称冲突时如何从 typescript.d.ts 文件访问接口?的主要内容,如果未能解决你的问题,请参考以下文章