Question presented to candidate: "What is a literal type in TypeScript? Show me where you would use one, and explain why `const x = 'up'` and `let x = 'up'` end up with different types."
What a strong answer should cover:
- A literal type is a type with exactly one value (`"up"`, `42`, `true`); a union of literals models a closed set of allowed values
- `boolean` is just `true | false`; string, number, boolean and bigint literals all exist
- Widening: `const` keeps the literal type, `let` and object-literal properties widen to `string` / `number`, which is the classic "string is not assignable to 'GET' | 'POST'" error
- The fixes: annotate with the union, use `as const`, or derive the union from a const array with `(typeof ARR)[number]`
- Comparing against a literal (`===`, `switch`) narrows the union, enabling exhaustiveness checks with `never`
- Literal types are erased: untrusted strings still need a run-time guard
Code / implementation expected: Yes β a function that accepts a literal union, a widening error and its fix.