All challenges
Type-Safe Event Emitter
hardgenerics200 XPProblem
Build a TypedEmitter<E> class where E maps event names to payload types (for example, "score" carries a number and "message" carries a string). Implement on<K extends keyof E>(event: K, handler: (payload: E[K]) => void) and emit<K extends keyof E>(event: K, payload: E[K]). Emitting "score" with a string, or subscribing to an unknown event name, must be a compile error.
Expected output
Score: 99
Message: HELLOHints
Stuck? Reveal hints one at a time.
Solution
Try solving it yourself first — revealing is always available.
Press Run in the editor — your console output is checked automatically.
No errors
Loading...
Console output appears here. Press Run or just type — the code compiles automatically.