

Event Router
An app emits three kinds of event, modelled as a discriminated union on kind. Write describeEvents(events) that turns each event into one line of text:
- click:
click at (X, Y) - key:
key K, orshortcut Ctrl+Kwhenctrlis true - scroll:
scroll down Nfor a positive delta,scroll up Nfor a negative one (N is always positive)
Handle every kind in a switch, and finish with a never check so adding a fourth kind later becomes a compile error instead of a silent bug.
Examples
describeEvents([{ kind: "click", x: 10, y: 20 }, { kind: "key", key: "s", ctrl: true }, { kind: "scroll", delta: -40 }])
→ ["click at (10, 20)", "shortcut Ctrl+s", "scroll up 40"]
describeEvents([{ kind: "key", key: "Enter", ctrl: false }, { kind: "scroll", delta: 15 }])
→ ["key Enter", "scroll down 15"]
project.ts
TYPESCRIPT
Saved as you type
Tests
0 of 3 passing- •one of eachdescribeEvents([{ kind: "click", x: 10, y: 20 }, { kind: "key", key: "s", ctrl: true }, { kind: "scroll", delta: -40 }])expected ["click at (10, 20)", "shortcut Ctrl+s", "scroll up 40"]
- •plain key and scroll downdescribeEvents([{ kind: "key", key: "Enter", ctrl: false }, { kind: "scroll", delta: 15 }])expected ["key Enter", "scroll down 15"]
- •no eventsdescribeEvents([])expected []
On the line
+340 XP
Pass all 3 tests to claim it.
