存储对命名空间的引用而不是类型

Store reference to namespace instead of type

假设我有这样一个命名空间:

export namespace Foo1 {
  export namespace Foo2 {
    export namespace Foo3 {
      export interface Foo4 {}
      export interface Foo5 {}
    }
  }
}

在 .ts 文件中我有这样的东西:

import {Foo1} from './foo';

const bar1 = function(){
   type t = Foo1.Foo2.Foo3.Foo4;
}

const bar2 = function(){
   type t = Foo1.Foo2.Foo3.Foo5;
}

这可能会有点冗长,我希望改为执行以下操作:

import {Foo1} from './foo';

type Foo3 = Foo1.Foo2.Foo3;  // <<< this don't work, I get an error explained below

const bar1 = function(){
   type t = Foo3.Foo4;
}

const bar2 = function(){
   type t = Foo3.Foo5;
}

但我似乎无法存储对命名空间的引用,我只能存储对类型的引用? (我得到的错误是命名空间 Foo2 没有导出成员 Foo3)。

我这样试过,效果很好

    namespace Shapes {
    export namespace Polygons {
        export namespace Square {
            export interface Foo4 {}

        }

        export namespace Triangle {
            export interface Foo5 {}
        }
    }
}


import polygons = Shapes.Polygons;

type myType = polygons.Square.Foo4;

export class myClass implements polygons.Square.Foo4{
    myFoo4 = 'Foo4';

}


const myFooInstance = new myClass();

console.log(myFooInstance.myFoo4);