Event Emitter with Type-safe Events
HardCreate 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
TypeScript•UTF-8
Run your code to see results.
Click the Run button above
Event Emitter with Type-safe Events
HardCreate 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.