Question presented to candidate:
"What is a conditional type in TypeScript? Write one, explain what extends means inside it, and tell me where you have seen them used."
What a strong answer should cover:
- The form
T extends U ? X : Y: a type-level if/else that picksXwhenTis assignable toU, otherwiseY; added in TypeScript 2.8 extendsmeans assignability, not equality: literals fit their wide type, objects with extra properties fit,anygives both branches, the first match in a chain wins- Deferred resolution: inside a generic function the condition is unresolved, so returning a concrete value needs a cast (or overloads)
inferto pull a type out of a pattern (T extends (infer E)[] ? E : T), and that the standardExclude,ExtractandReturnTypeare conditional types (NonNullablestarted as one in 2.8 but isT & {}in today's lib)- When the checked type is a naked type parameter the condition distributes over unions (its own topic), and
neverthen givesnever - Trade-off against function overloads for return types that depend on arguments
Code / implementation expected: Yes β a small conditional type such as TypeName<T> or a return type that depends on an argument.