0 of 5 problems solved0%
4 of 5

Toggle Theme (Inference at Work)

Instead of stating : boolean, let TypeScript infer the type through assignment.

Your Task

  1. Assign true or false to isDarkMode. This infers the type as boolean.
  2. Complete the function toggle(). It should toggle isDarkMode between true and false.
  3. Call toggle() twice and log isDarkMode each time.

Why it's neat:
TS infers isDarkMode as boolean automatically. Try passing a string to toggle() and see how TS protects you.