Question presented to candidate:
"You have a route map or theme config checked with satisfies. Which literal types survive and which still widen? Walk me through why, and when you would add as const."
What a strong answer should cover:
satisfies TsuppliesTas the contextual type; a literal is kept when the contextual type at that position contains literal types of the same kind, and widened otherwise- So
{ mode: "dark" } satisfies { mode: "dark" | "light" }keeps"dark", butsatisfies { mode: string }orRecord<string, unknown>givesstring - Keys are always kept:
keyof typeof routesis"home" | "about", while an annotation withRecord<string, string>turns keys intostringand accepts typos satisfies Record<Union, V>makes a map exhaustive: a missing or extra key is a compile erroras const satisfies Tgives validated, deeply readonly literals; the order matters (satisfies T as constis error TS1355); with arrays, check against areadonlyarray type- A tuple target such as
[number, number]produces a tuple withoutas const
Clarifying questions expected:
- Should the values be readonly constants, or will they be changed later?
- Do callers need the literal values (for example to derive a union of paths) or only the keys?
Code / implementation expected: Yes β the same object checked against a literal-union target and a string target, with Equal checks proving which literals survive, plus an as const satisfies route map.