Type-Safe Event Emitters in TypeScript

Node's EventEmitter is one of the most used primitives in server-side JavaScript. It's also a refactoring minefield — every event name is a string, every payload is any, and nothing stops you from emitting an event nobody is listening to or wiring a listener that expects the wrong shape. TypeScript can enforce all of this at compile time, and the setup is simpler than most teams assume.

The default API offers zero type safety on event names or payloads.