01
Overview
Conditional types branch at the type level. T extends U ? X : Y. infer extracts types. distributive over unions. Exclude, Extract, NonNullable built on conditionals. Use for type-safe utilities.
bash
type IsString<T>=T extends string?true:false;
type Unbox<T>=T extends Promise<infer U>?U:T;
type Props<T>=T extends Array<infer I>?{items:T[];render:(x:I)=>void}:{value:T};
// Distributive
type Exclude2<T,U>=T extends U?never:T;02
Best Practices
Use conditional types for type-level logic. infer to extract from generic types. Distributive over unions (wrap in [T] to disable). Use built-in Exclude/Extract/NonNullable. Keep complex types documented. Test with tsd or expectType.)
Ready to try Conditional Types?
Visit the official site for the latest version and full documentation.
Visit Conditional Types