TypeScript tutorialLesson 28Free preview
TS Conditional Types
This lesson is part of TypeScript · All levels
Summary
Conditional type decides type based on the relationship extends, with the pattern T extends U? X : Y. When T is a union, the conditional is distributive to each member. The infer operator is used to extract subtypes such as the type of argument or the return of a function.
Key points
- The basic pattern: T extends U? X: Y
- Union triggers conditional distributive
- Infer captures a sub-type of the matched type
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.