Skip to content
GreenSnippets

Check an object against a type with satisfies

Validate a config object against an interface while keeping its precise literal types.

TypeScript
type Route = { path: string; auth?: boolean };

const routes = {
  home: { path: "/" },
  account: { path: "/account", auth: true },
} satisfies Record<string, Route>;

type RouteName = keyof typeof routes; // "home" | "account"

function pathFor(name: RouteName): string {
  return routes[name].path;
}

Example / expected output

Output
pathFor("account"); // "/account"
pathFor("missing"); // compile error

How it works

A type annotation (const x: Config = ...) widens values to the declared type and forgets literals. satisfies checks the shape without widening, so you get both validation and autocompletion on the exact keys and values you wrote. Combine with as const for readonly tuples.