内部模块与外部模块同名

时间:2015-03-12 21:15:16

标签: typescript

我有一些javascript库的定义。假设它的功能可以通过模块名称Lib来访问。

与此同时,我创建了这样的模块:

module Outer.Lib.Inner {
  // some code
}

如何在我自己的模块Outer.Lib.Inner中访问外部模块Lib?我试过这样的方式:

module Outer.Lib.Inner {
  function SomeFunction(): void {
    // here i am trying to access outer Lib module but compiler thinks i am accessing my Outer.Lib module
    Lib. ....
  
  }
}

提前致谢。

1 个答案:

答案 0 :(得分:4)

  

如何在这种情况下限定外部模块的名称?

由于外部模块Lib的完全限定名称与我们在Outer.Lib中的内部模块声明冲突,您需要创建一个别名:

var ExternalLib = Lib; 
// or if you have it in TypeScript: 
// import ExternalLib = Lib;


module Outer.Lib.Inner {
  function SomeFunction(): void {
    // here i am trying to access outer Lib module but compiler thinks i am accessing my Outer.Lib module
    ExternalLib. ....

  }
}
相关问题