// Define your event types
interface MyEvents {
'turtle:moved': [x: number, y: number];
'inventory:full': [];
'fuel:low': [remainingFuel: number];
}

// Create your emitter
const events = new EventEmitter<MyEvents>();

// Listen for events
events.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:

  • Building reactive user interfaces
  • Managing turtle state changes
  • Coordinating multiple computers
  • Implementing pub/sub patterns

A record of event names mapped to their argument types

Classes

EventEmitter

Type Aliases

EventMap