Conditional Types
Prerequisites: Advanced generics
A conditional type picks between two types based on a check, evaluated entirely at the type level.
type IsString<T> = T extends string ? "yes" : "no";
type A = IsString<string>; // "yes"
type B = IsString<number>; // "no"
This is how many of TypeScript's own built-in utility types (like
Exclude and ReturnType) are implemented under the hood — the type
system itself can express this kind of "if/else" logic.