Q18. What is a conditional type?
A conditional type T extends U ? X : Y selects a type based on assignability. When the checked side is a naked type parameter, it distributes across union members. Tuple wrapping can suppress that distribution.
Conditional types let type-level logic select outputs based on input types without runtime execution.
Note
Interview approach: define the concept, explain why it matters, then mention one trade-off or limitation.
TypeScript concept
// Illustrative TypeScript contract
type Identifier = string;
const id: Identifier = "item-1";💡 The example demonstrates the compile-time contract discussed in this question.
Key Takeaways
- Explain the concept in your own words.
- Know the practical trade-off and its limits.
- Use a small example to demonstrate the idea.
Knowledge Check
What is the basic syntax of a conditional type?