Most usable way of doing this, is to use declare
:
declare interface MyClass {
on(event: 'hello', listener: (name: string) => void): this;
on(event: string, listener: Function): this;
}
class MyClass extends events.EventEmitter {
emitHello(name: string): void {
this.emit('hello', name);
}
}
Note that if you are exporting your class, both the interface and class have to be declared with the export
keyword.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…