ee-typed
TypeScript version of the nodejs events
module.
Usage
This is just the built-in nodejs event emitter with type information added, so you can use it like the official docs:
import { EventEmitter } from 'ee-typed';
type Events = {
event(): void;
};
class MyEmitter extends EventEmitter<Events> {}
const myEmitter = new MyEmitter();
myEmitter.on('event', () => {
console.log('an event occurred!');
});
myEmitter.emit('event');
myEmitter.emit(42);
Based on typed-emitter
This package builds on typed-emitter
.
typed-emitter
has the advantage of being a type-only library, so it adds zero bytes to your bundle. However, that approach requires you to import the regular events
library and then cast to the provided type.
This library provides the actual class with the appropriate cast, which I feel is simpler. Worthy of the few dozen bytes it adds to your bundle I'd say.