Is there any way to treat an interface or a variable inside a typescript declaration file like class to be able to extend a class from it?
Like this:
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;
};
}
Right now i have to redefine the EventEmitter interface like this and use my own EventEmitter declaration.
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;
};
And extend it later inside my TypeScript File
import tedious = module('tedious');
class Request extends tedious.Request {
private _myVar:string;
constructor(sql: string, callback: Function){
super(sql, callback);
}
}
I dunno about back in 2013, but now it's easy enough:
/// <reference path="../typings/node/node.d.ts" />
import * as events from "events";
class foo extends events.EventEmitter {
constructor() {
super();
}
someFunc() {
this.emit('doorbell');
}
}
I was looking for the answer to this, and finally figured it out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With