Event Emitter with Type-safe Events

Hard

Create a typed EventEmitter for Hack Frontend application. Events should be strictly typed with correct payload types.

Requirements:

  • on/emit methods with event name autocomplete
  • Payload types must match the event
  • Cannot emit with wrong payload

Examples:

Input 1: emitter.on("courseCompleted", (data) => ...)
Output 1: data: { courseId: string; userId: number }
Output
Run your code to see results.