0Pricing
TypeScript Academy · Lesson

Practical satisfies Patterns

Apply satisfies to config objects and lookup tables.

Practical satisfies Patterns is a free TypeScript Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Validating a Color Palette

A common pattern is satisfies Record<string, Color> for a palette: every value is checked to be a valid color, while keys stay exact for autocomplete.

type Color = "red" | "green" | "blue";
const palette = {
  primary: "blue",
  secondary: "green"
} satisfies Record<string, Color>;
console.log(palette.primary);

Catching Invalid Palette Values

If a value is not a valid Color, satisfies errors, while the keys remain precisely typed.

type Color = "red" | "green" | "blue";
// const bad = { primary: "purple" } satisfies Record<string, Color>; // Error
const ok = { primary: "red" } satisfies Record<string, Color>;
console.log(ok.primary);

Keeping Key Autocomplete

Because the inferred keys are "primary" | "secondary", your editor autocompletes them, unlike a plain Record annotation which would lose specific keys.

type Color = "red" | "green" | "blue";
const palette = { primary: "red", accent: "blue" } satisfies Record<string, Color>;
// palette.<autocomplete: primary, accent>
console.log(palette.accent);

Validating a Route Map

Route maps benefit too: values must match a handler shape, while route names stay known for navigation helpers.

type Route = { method: "GET" | "POST"; path: string };
const routes = {
  home: { method: "GET", path: "/" },
  login: { method: "POST", path: "/login" }
} satisfies Record<string, Route>;
console.log(routes.login.method);

Indexing Into the Map

With keys preserved, you can build a type of valid route names and index into the map type-safely.

type Route = { method: string; path: string };
const routes = {
  home: { method: "GET", path: "/" },
  about: { method: "GET", path: "/about" }
} satisfies Record<string, Route>;
type RouteName = keyof typeof routes; // "home" | "about"
const pick: RouteName = "about";
console.log(routes[pick].path);

Typed Config With Mixed Values

satisfies works when values have different shapes too. Constrain with a union type and each value is validated against it.

type Setting = number | boolean | string;
const config = {
  retries: 3,
  verbose: true,
  region: "eu"
} satisfies Record<string, Setting>;
console.log(config.retries, config.verbose);

Enum-Like Lookup Tables

Build a lookup table validated against a value type while keeping each entry exact for later use.

type Status = "active" | "inactive";
const userStatus = {
  alice: "active",
  bob: "inactive"
} satisfies Record<string, Status>;
const s: "active" = userStatus.alice;
console.log(s);

Pairing With as const

Combine as const and satisfies for deeply immutable, validated data: as const freezes it, satisfies checks it.

type Color = "red" | "blue";
const theme = {
  primary: "red",
  secondary: "blue"
} as const satisfies Record<string, Color>;
console.log(theme.primary);

Validating Numeric Ranges by Type

You can constrain values to a numeric literal union to model fixed option sets, validated at definition time.

type Level = 1 | 2 | 3;
const levels = {
  easy: 1,
  medium: 2,
  hard: 3
} satisfies Record<string, Level>;
console.log(levels.hard);

A Feature Flag Map

A practical feature-flag config: keys are flag names you autocomplete, values are booleans validated by satisfies.

const flags = {
  newDashboard: true,
  betaSearch: false
} satisfies Record<string, boolean>;
type Flag = keyof typeof flags;
const f: Flag = "betaSearch";
console.log(flags[f]);

Why This Pattern Wins

Across palettes, routes, and flags, satisfies Record<...> gives validated values plus precise keys and literals, the everyday sweet spot for typed configuration.

type Color = "red" | "green" | "blue";
const ui = { brand: "green", warn: "red" } satisfies Record<string, Color>;
console.log(Object.keys(ui).join(","));

Quick Check: Practical satisfies

Test your understanding of practical satisfies patterns.

Recap: Practical satisfies Patterns

You applied satisfies Record<string, Color> to palettes, route maps, flags, and lookup tables, keeping exact keys and literals for autocomplete while validating every value.

type Color = "red" | "blue";
const theme = { bg: "blue", fg: "red" } satisfies Record<string, Color>;
console.log(theme.bg, theme.fg);

Frequently asked questions

Is the “Practical satisfies Patterns” lesson free?

Yes — the full text of “Practical satisfies Patterns” is free to read here on the web, and the TypeScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.

What will I learn in “Practical satisfies Patterns”?

Apply satisfies to config objects and lookup tables. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start TypeScript Academy?

No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Practical satisfies Patterns” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this TypeScript Academy lesson?

Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Why satisfies Exists
  2. satisfies vs Type Annotation
  3. satisfies vs as Assertion
  4. Practical satisfies Patterns
← Back to TypeScript Academy