Question presented to candidate:
"What do ReturnType and Parameters do? When have you used them, and what are their limits — say with overloads or generic functions?"
What a strong answer should cover:
ReturnType<F>gives the return type of a function type;Parameters<F>gives its parameter types as a (labelled) tuple; both need a function type, so you passtypeof fn- They are conditional types with
infer(F extends (...args: any) => infer R ? R : any) - Uses: name a type nobody exported, type wrappers and decorators that keep a signature (
(...args: Parameters<F>) => ReturnType<F>), forward arguments;ConstructorParametersandInstanceTypefor classes - Async functions:
ReturnTypeis thePromise; combine withAwaitedfor the resolved value - Limits: overloads use only the last signature, generic functions get their constraint (
unknown) unless you pin the type with an instantiation expression, and non-functions are rejected by the constraint
Code / implementation expected: Optional — a withLog wrapper using both, or MyReturnType with infer.