36 lines · 988 B · Markdown
RawDownload

title: "TypeScript: Satisfies operator" date: "2025-06-08" tags:

  • Reading

Typescript 4.9 introduced the new satisfies operator.

Steve explains it best using this example:

type Route = { path: string; children?: Routes };
type Routes = Record<string, Route>;

const routes = {
  AUTH: {
    path: "/auth",
    children: {
      LOGIN: {
        path: "/login",
      },
    },
  },
  HOME: {
    path: "/",
  },
} satisfies Routes;

routes.AUTH.path; // works
routes.AUTH.children.LOGIN.path; // works
routes.HOME.children.LOGIN.path; // error
//          ^? Property 'children' does not exist on type '{ path: string; }'.

Matt Pocock has a great example of a use-case in his TypeScript 4.9 deep dive video.