satisfies
An operator, value satisfies Type, that checks a value matches a type without changing the value's own, more precise inferred type.
In more detail
An annotation such as const theme: ThemeConfig widens each property to the declared type, while satisfies keeps "#3b82f6" as a string so string methods still work. It catches misspelled or missing keys like an annotation does. Combine it with as const for validated, immutable configuration.
Example
const theme = { primary: "#3b82f6", secondary: [16, 185, 129] } satisfies ThemeConfig;Related terms
- type annotation — A type written explicitly after a name with a colon, such as name: string, to tell the compiler what a value must be.
- as const — The TypeScript suffix as const, which tells the compiler to treat an object's values as fixed literal values rather than general types.
- type widening — The compiler giving a value a broader type than its exact value, such as string instead of "production", because it might change later.
- type assertion (TypeScript) — Writing value as Type to tell the compiler to treat a value as a type, without any check that it really is.
Taught in
- Verify Your Environment: Running tsc And Bun TypeScript — Production TypeScript
- Declaration Files, Ambient Namespaces And Module Augmentation — Production TypeScript
- The satisfies Operator: Safe Validation Without Widening — Production TypeScript