TEventEmitter
TEventEmitter is an enhanced event emitter that supports type-safe event keys. With TEventEmitter, you can create string or symbol keys and ensure type safety when emitting and listening to events.
Usage Example
Here's a quick example demonstrating how to use TEventEmitter to create and handle type-safe events:
import { TEventEmitter } from 't-event-emitter';
const emitter = new TEventEmitter();
const key = emitter.createKey<[number, string]>('myEvent');
emitter.on(key, (num, str) => {
console.log(`Number: ${num}, String: ${str}`);
});
emitter.emit(key, 42, 'Hello, World!');