Man*_*uel 5 interface class declaration extend typescript
有没有办法处理类型脚本声明文件(如类)中的接口或变量,以便能够从中扩展类?
像这样:
declare module "tedious" {
import events = module('events');
export class Request extends event.EventEmitter {
constructor (sql: string, callback: Function);
addParameter(name: string, type: any, value: string):any;
addOutputParameter(name: string, type: any): any;
sql:string;
callback: Function;
};
}
Run Code Online (Sandbox Code Playgroud)
现在我必须像这样重新定义EventEmitter接口并使用我自己的EventEmitter声明.
import events = module('events');
class EventEmitter implements events.NodeEventEmitter{
addListener(event: string, listener: Function);
on(event: string, listener: Function): any;
once(event: string, listener: Function): void;
removeListener(event: string, listener: Function): void;
removeAllListener(event: string): void;
setMaxListeners(n: number): void;
listeners(event: string): { Function; }[];
emit(event: string, arg1?: any, arg2?: any): void;
}
export class Request extends EventEmitter {
constructor (sql: string, callback: Function);
addParameter(name: string, type: any, value: string):any;
addOutputParameter(name: string, type: any): any;
sql:string;
callback: Function;
};
Run Code Online (Sandbox Code Playgroud)
稍后在我的TypeScript文件中扩展它
import tedious = module('tedious');
class Request extends tedious.Request {
private _myVar:string;
constructor(sql: string, callback: Function){
super(sql, callback);
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道 2013 年的情况,但现在很简单:
/// <reference path="../typings/node/node.d.ts" />
import * as events from "events";
class foo extends events.EventEmitter {
constructor() {
super();
}
someFunc() {
this.emit('doorbell');
}
}
Run Code Online (Sandbox Code Playgroud)
我一直在寻找这个问题的答案,最后终于找到了答案。
| 归档时间: |
|
| 查看次数: |
5657 次 |
| 最近记录: |