我目前正在尝试为OpenLayers构建TypeScript定义文件。TypeScript模块和类同时?
的问题是,在的OpenLayers有将转化为双方的模块和打字稿一类特定的类。
例如,模块OpenLayers
中有Protocol
类,模块OpenLayers.Protocol
中有Response
类。
我怎么能模式,在打字稿?我可以让Protocol
为类,并将Response
类定义为导出的内部类吗?你将如何去解决这个问题?
我目前正在尝试为OpenLayers构建TypeScript定义文件。TypeScript模块和类同时?
的问题是,在的OpenLayers有将转化为双方的模块和打字稿一类特定的类。
例如,模块OpenLayers
中有Protocol
类,模块OpenLayers.Protocol
中有Response
类。
我怎么能模式,在打字稿?我可以让Protocol
为类,并将Response
类定义为导出的内部类吗?你将如何去解决这个问题?
这里是我更新的答案,我希望帮助 - 它应该让你开始定义的OpenType:
declare module OpenType {
export class Protocol {
constructor();
Request;
}
}
var x = new OpenType.Protocol();
var y = new x.Request();
var z = x.Request;
声明Response
为Protocol
使用构造类型static
场,返回一个interface
定义Response
类:
declare module OpenLayers {
export interface IProtocolResponse {
foo(): void;
}
export class Protocol {
static Response: new() => IProtocolResponse;
}
}
var response = new OpenLayers.Protocol.Response();
response.foo();
编辑:
或者像安德斯在this discussion list question指出,你可以有这样的内部类多个构造函数:
declare module OpenLayers {
export interface IProtocolResponse {
foo(): void;
}
export class Protocol {
static Response: {
new(): IProtocolResponse;
new (string): IProtocolResponse;
};
}
}
var response = new OpenLayers.Protocol.Response('bar');
response.foo();
这两种方法的主要缺点是,你不能从OpenLayers.Protocol.Response
派生类。
的可能的复制[任何方式来声明在打字原稿巢类结构?](http://stackoverflow.com/questions/13495107/any-way-to-declare-a-nest-class-structure-in-打字稿) – Alex