Hone

Lessons · TypeScript · satisfies

Check the shape, keep the detail

value satisfies Type checks the value fits Type without widening its inferred type.

Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.

What it is for

Config tables typed as Record<string, X> lose the literal keys, so cfg.theme stops autocompleting. satisfies validates and keeps them.

How to think about it

Do I need the exact keys afterwards? Use satisfies for literal objects that must match a contract but whose exact keys you want to keep using.

Worked example

const LEVELS = { debug: 10, info: 20 } satisfies Record<string, number>;
Checked against the record type.
LEVELS.info
Still known to exist and be a number; with ': Record<string, number>' it would be number | undefined.

Your turn

Validate without widening.

const routes = { home: "/", about: "/about" }  Record<string, string>;

The trap

Using 'as Type' instead. as suppresses errors; satisfies reports them.

Practise satisfies on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.