satisfies vs Type Annotation
Keep literal inference while still validating shape.
The Annotation Pattern
The classic pattern const config: Type = {...} validates the object but the variable type becomes Type, widening any literals inside.
type Config = { mode: string; level: number };
const config: Config = { mode: "dark", level: 5 };
// config.mode has type string
console.log(config.mode);What Widening Looks Like
With the annotation, config.mode is string. You cannot assign it to a variable expecting the literal "dark".
type Config = { mode: string };
const config: Config = { mode: "dark" };
// const m: "dark" = config.mode; // Error: string not assignable to "dark"
console.log(config.mode);All lessons in this course
- Why satisfies Exists
- satisfies vs Type Annotation
- satisfies vs as Assertion
- Practical satisfies Patterns