Skip to content
Star16Hire me
01 / StartXP 0%
Sep 1, 2026 · 1 min · by Ahmed Mamdouh

Use satisfies before you reach for as in TypeScript

#typescript#nodejs#code-review

The TypeScript keyword I see misused most is as. Most of the time the author wanted satisfies, which checks the shape and keeps the narrow type.

What as actually does

Every as SomeType tells the compiler to stop checking that expression. Sometimes you need that. Usually you don't.

type Config = { port: number; host: string };
 
// Compiles fine, even though host is missing
const a = { port: 3000 } as Config;
 
// Error: property 'host' is missing
const b = { port: 3000 } satisfies Config;

What satisfies gives you

satisfies validates the value against the type and leaves the inferred type alone. You get the check, and you keep the precise literal types instead of widening everything to the annotation.

const routes = {
  home: "/",
  blog: "/blog",
} satisfies Record<string, string>;
 
routes.home; // still known to exist, typed as string

The rule I give my team

If you write as, add a comment explaining why the compiler is wrong. If you can't write that comment, the compiler isn't wrong.

The codebase got noticeably safer once we started enforcing that one habit in review.

Building something like this?

I'm Ahmed Mamdouh, a senior full-stack and AI engineer. I reply within one working day.

More posts