Command Palette

Search for a command to run...

Hectal
Phase 13: TypeScript in the Browser: DOM and Async
TypeScript · Exercise 4 of 6 PreviousNext
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

  1. Your code has no type errors
  2. The listener logs done 3 Buy milk
  3. A listener sees detail.id as a number
  4. A field that is not in the detail is rejected
  5. 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.