Conditional Type
Question
What is a conditional type?
Hint
T extends U ? X : Y selects X if T extends U, else Y.
Explanation
A conditional type selects one of two types based on whether a type extends another. Syntax: T extends U ? X : Y. If T is assignable to U, the result is X; otherwise Y. Example: type IsString<T> = T extends string ? true : false. Conditional types enable powerful type-level programming: distributive conditional types, the infer keyword (type inference within conditions), and the Exclude/Extract utility types (built with conditionals). They are essential for advanced generic utilities.
Related Resources
Related Lessons
- Conditional Types
Learn conditional types.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.