Published on

TypeScript Trick #1: satisfies – Your New Best Friend 😎

Have you ever written an object in TypeScript, and just hoped it matches the right type? Let’s be honest – we’ve all been there. Sometimes TypeScript is too smart and lets things slip through… or complains when it shouldn’t.

That’s where satisfies comes in. This keyword checks if your object fits a type, without losing any of the exact values you wrote. Think of it as a quick type-checking tool that doesn’t mess with your autocomplete or inferred types.

Quick Example:

type User = {
  id: number;
  name: string;
};

const user = {
  id: 42,
  name: "Dominik",
  extra: true
} satisfies User;
// ❌ Error: Object literal may only specify known properties

// But this is fine:
const user2 = {
  id: 1,
  name: "Dominik"
} satisfies User; // ✅

Why do I love it?

  • Catches mistakes early: You instantly know if you forgot a property or added something you shouldn’t.
  • Keeps your original object shape: No forced type-casting or losing your precious autocomplete.
  • Great for config objects and enums: Your data stays correct and typesafe.
avatar

A practical blog about TypeScript, React, and modern front-end development. Real-world tips, code breakdowns, and honest takes for developers who want to build better web apps—without the hype.

Subscribe to the newsletter