×

typescript · level 3 · unit 2 · lesson 2

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

checks a value without forgetting its details.

A type annotation, like const loose: Colours = {...}, checks the value and then forgets it. From that line on, TypeScript only knows the annotation. With Record<string, string> it thinks any key might exist, so a typo like loose.purple slips through as undefined.

satisfies checks the value against a type and keeps what it learned about the value itself. Write it after the value: { red: "#f00" } satisfies Colours. Wrong values are still caught, and every exact key stays known.

type Colours = Record<string, string>;
const loose: Colours = { red: "#f00", green: "#0f0" };
const exact = { red: "#f00", green: "#0f0" } satisfies Colours;
console.log(loose.purple);
console.log(exact.red.toUpperCase());

An annotation goes before the =, while satisfies goes after the value.