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
- Your code has no type errors
- The console prints
#111 - Your code uses
satisfies bgaccepts both modesbgrejects an unknown mode- 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.
Press Run to see the page.
Console
Nothing printed yet.