如何在 TypeScript 中导入名称空间前缀等于自己名称空间后缀的模块(别名)?
How to import module(alias) whoes namespace's prefix equals own namespace's suffix in TypeScript?
当我编译下面的代码时,tsc 编译器输出错误信息。
代码:
module a {
export class Foo {}
}
module b.a {
import Foo = a.Foo;
class Bar {}
}
错误信息:
sample.ts(5,5): error TS2305: Module 'b.a' has no exported member 'Foo'.
能告诉我为什么会出现编译错误吗?
如果有任何解决方案?
提前致谢。
a
在模块 a
的上下文中(包括子模块 b.a
)是指模块 a
。考虑到模块代码的生成方式,这是必需的。
您可以在 'wrong' a
不可见的地方创建别名:
module a {
export class Foo {}
}
import global_a = a;
module b.a {
import Foo = global_a.Foo;
class Bar {}
}
当我编译下面的代码时,tsc 编译器输出错误信息。
代码:
module a {
export class Foo {}
}
module b.a {
import Foo = a.Foo;
class Bar {}
}
错误信息:
sample.ts(5,5): error TS2305: Module 'b.a' has no exported member 'Foo'.
能告诉我为什么会出现编译错误吗? 如果有任何解决方案? 提前致谢。
a
在模块 a
的上下文中(包括子模块 b.a
)是指模块 a
。考虑到模块代码的生成方式,这是必需的。
您可以在 'wrong' a
不可见的地方创建别名:
module a {
export class Foo {}
}
import global_a = a;
module b.a {
import Foo = global_a.Foo;
class Bar {}
}