T extends U ? X : Y in practice
Write practical conditional types; learn distribution over unions and how to opt out when needed.
Intro
Goal: Use conditional types to express logic in the type system and understand when they distribute over unions.
- Pattern:
T extends U ? X : Y - Distribution: applies branch per union member
Basic pattern
Conditional types pick a branch based on whether T is assignable to string.
type IsString<T> = T extends string ? true : false
type A = IsString<string>
// ^ true
type B = IsString<number>
// ^ falseAll lessons in this course
- T extends U ? X : Y in practice
- infer for ReturnType-like utilities
- Built-ins: ReturnType, Parameters, InstanceType, etc.