satisfies

Annotations widen

A wide annotation like a Record of string to string erases literal detail. Every value becomes plain string and exact keys are forgotten.

Wide is just string, so the sky literal blue is lost. Autocomplete and typo checks suffer the same way.

const palette: Record<string, string> = { sky: "blue", leaf: "green", }; type Wide = typeof palette.sky; // string

Check with satisfies

satisfies checks the value against a shape without widening it. The object must fit a Record of string to string, yet keeps its own narrow type.

A wrong value or a non-string still fails the check. Valid code passes with literals intact.

const theme = { sky: "blue", leaf: "green", } satisfies Record<string, string>;

Keep literal types

Because the literal types survive, indexed access reads them back exactly. Sky is the single string blue rather than the whole string type.

Hover info and autocomplete now show real values. Refactors stay safe since misspelled keys fail at once.

type Sky = (typeof theme)["sky"]; // "blue" const sky: Sky = "blue";

Export exact shapes

typeof theme exports the exact shape for reuse across the codebase. Functions and props can share one source of truth.

current must match the theme keys and value literals. One definition drives them all with no drift.

type Theme = typeof theme; const current: Theme = { sky: "blue", leaf: "green", };

Next: const assertions

Article author: Arthur Isaev