CodePark/ questions / Functions & satisfies
START PRACTICINGPRACTICE
Frontend question · TypeScript › Functions & satisfies

With default strict settings, which line errors?

type Routes = Record<string, string>;
const a: Routes = { home: "/", blog: "/blog" };
const b = { home: "/", blog: "/blog" } satisfies Routes;
a.about;   // Line 4
b.about;   // Line 5
Only Line 5

Only Line 5 errors. b keeps its inferred type { home: string; blog: string }, so about does not exist on it. This precision is the main reason to use satisfies.

"Both lines" is wrong because Line 4 compiles.
a is annotated as Record<string, string>, so any string key is allowed.