我想知道是否有可能以某种方式在两个或多个文件中添加两个或多个文件到TypeScript中的相同模块。类似这样的:TypeScript模块
//src/gui/uielement.ts
module mylib {
module gui {
export interface UIElement {
public draw() : void;
}
}
}
//src/gui/button.ts
///<reference path='uielement.ts'/>
module mylib {
module gui {
export class Button implements UIElement {
constructor(public str : string) { }
draw() : void { }
}
}
}
可能会有几十个GUI类,因此将它们都放在同一个文件中是不可能的。而我所有的课程都将放在'mylib'模块中。 但我该怎么做?
如果将module mylib {...}
翻译为函数,则所有文件中所有mylib
块的所有内容都应包含在同一个函数中。
这是可能的吗?
当我编译我得到这个:
$ tsc src/gui/button.ts
src/gui/button.ts(4,39): The name 'UIElement' does not exist in the current scope
是的,这是支持的。不知道你为什么不试试它。 –
我做到了。对不起,没有解释我得到的错误...将进一步描述。 –