TypeScript为"类"使用"别名"/别名

sam*_*ime 3 alias module class typescript

有没有办法为TypeScript类/模块执行别名或"使用"(如PHP).

例:

如果我有:

module Foo {
    class Bar {}
}
Run Code Online (Sandbox Code Playgroud)

通常我必须编写Foo.Bar以在模块之外使用它.有没有办法可以将其别名,比如"FooBar".

如果你有几个子模块(我当前的项目所做的),这将非常有用,例如:

模块ABCD {export class E {}}

通常A.B.C.D.E是愚蠢的.

Dax*_*x70 6

根据旧的Typescript语言规范的第82页,它声明以下是可能的.因此,您应该能够别名"使用"模块,而无需引用整个层次结构.

module A.B.C
{
  import XYZ = X.Y.Z;

  export function ping(x: number) {
    if (x > 0) XYZ.pong(x – 1);
  }
}

module X.Y.Z
{
  import ABC = A.B.C;

  export function pong(x: number) {
    if (x > 0) ABC.ping(x – 1);
  }
}
Run Code Online (Sandbox Code Playgroud)

新的Typescript语言规范涵盖了" 导入别名声明"一节中的类似材料