What are conditional types in TypeScript?
Why Interviewers Ask This
Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.
Answer
Conditional types allow types to vary based on a condition, using a ternary-like syntax: T extends U ? X : Y — "if T is assignable to U, the type is X; otherwise, it is Y." Example: type IsString<T> = T extends string ? "yes" : "no";. Combined with generics, conditional types become very powerful: type NonNullable<T> = T extends null | undefined ? never : T. Distributive conditional types: when the checked type is a naked type parameter, the condition distributes over union members: IsString<string | number> becomes IsString<string> | IsString<number> which is "yes" | "no". Wrap in a tuple to prevent distribution: [T] extends [U]. Infer: the infer keyword within conditional types lets you capture a type into a variable: type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never. Conditional types power many advanced utility types.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.