Command Palette

Search for a command to run...

Hectal
Phase 10: Utility Types and Type-Level Patterns
TypeScript · Exercise 5 of 5 Previous
Advanced

A Complete Theme with satisfies

A theme must define colours for every Mode. Declare colors with satisfies Record<Mode, { bg: string }> so a missing mode is an error, while the function bg can still read colors[mode].bg.

The starter's colors is empty, so bg has a type error. Fill it in with a light and a dark entry. bg("dark") must print #111.

What Check tests

  1. Your code has no type errors
  2. The console prints #111
  3. Your code uses satisfies
  4. bg accepts both modes
  5. bg rejects an unknown mode
  6. A theme with a missing mode would be rejected

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.

Console

Nothing printed yet.