Intermediate
Announce a todo as done with a typed event
Teach TypeScript about a custom event named "todo:done" whose detail is { id: number; title: string } by adding it to HTMLElementEventMap inside declare global.
Then listen on the element #list and log done <id> <title>. The last line already dispatches the event.
Inside your listener e.detail.id must be a number without any cast.
What Check tests
- Your code has no type errors
- The listener logs done 3 Buy milk
- A listener sees detail.id as a number
- A field that is not in the detail is rejected
- No cast to CustomEvent
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Your page
Press Run to see the page.
Console
Nothing logged yet.