Conditional Types
T extends U ? X : Y picks a type by a condition.
Example
type IsStr<T> = T extends string ? "yes" : "no";
const a: IsStr<string> = "yes";
const b: IsStr<number> = "no";
console.log(a, b);Result
yes no
Exercise
Ternary in types.
T extends U X : Y
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.