// Define your event typesinterface MyEvents { 'turtle:moved': [x: number, y: number]; 'inventory:full': []; 'fuel:low': [remainingFuel: number];}// Create your emitterconst events = new EventEmitter<MyEvents>();// Listen for eventsevents.on('turtle:moved', (x, y) => { print(`Turtle moved to ${x}, ${y}`);});// Emit events with type safety!events.emit('turtle:moved', 42, 73); // Works! ✨events.emit('turtle:moved', "oops"); // Type error! 🚫 Copy
// Define your event typesinterface MyEvents { 'turtle:moved': [x: number, y: number]; 'inventory:full': []; 'fuel:low': [remainingFuel: number];}// Create your emitterconst events = new EventEmitter<MyEvents>();// Listen for eventsevents.on('turtle:moved', (x, y) => { print(`Turtle moved to ${x}, ${y}`);});// Emit events with type safety!events.emit('turtle:moved', 42, 73); // Works! ✨events.emit('turtle:moved', "oops"); // Type error! 🚫
Common Use Cases:
A record of event names mapped to their argument types
Example
Common Use Cases:
Type Param: Events
A record of event names mapped to their argument types