Peter Mekhaeil

TypeScript: Satisfies operator

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.