Question presented to candidate: "Write a TypeScript function that takes a required argument, an optional one, one with a default value, and then any number of extra arguments. How do you type each kind, and what rules does the compiler enforce about them?"
What a strong answer should cover:
- Optional parameter `b?: T`: callers may omit it, and inside the body its type is `T | undefined`
- Default parameter `b = 1`: optional for callers, never `undefined` inside, type inferred from the default; the default applies to `undefined` but not to `null`
- Rest parameter `...xs: T[]` (or a tuple type such as `...args: [x: number, y?: number]`), always last and only one
- Order rules: a required parameter cannot follow an optional one (TS1016); a default before a required parameter is allowed but then not skippable
- Function type expressions, spreading arrays into fixed parameters (needs a tuple, TS2556), and `Parameters<typeof f>`
- Callback parameters should not be marked optional unless callers may really omit them
Code / implementation expected: Yes β one function using each parameter kind, with calls that pass and fail type checking.