Skip to content

Instantly share code, notes, and snippets.

@SagnikPradhan
Created April 12, 2020 05:36
Show Gist options
  • Save SagnikPradhan/65c0c974441ca3c192e7cbdd1c9fd0ba to your computer and use it in GitHub Desktop.
Save SagnikPradhan/65c0c974441ca3c192e7cbdd1c9fd0ba to your computer and use it in GitHub Desktop.
Using EventEmitter3 with Typescript
import {EventEmitter} from 'eventemitter3';
interface EventsMap {
// EventName: Params[]
hello: [string];
}
class MyClass extends EventEmitter {
constructor() {
super();
this.emit('hello', 'Hello World');
}
}
const myClassInstance = new MyClass();
myClassInstance.on('hello', console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment