TSadvancedts-evergreen

Conditional types and infer

Types that branch.

A conditional type is an if/else at the type level — T extends U ? X : Y — and infer lets you capture a piece of a matched type, which is how ReturnType, ElementType, and Flatten are all built.

IsString<T> — a type-level predicate

TSintro
Press Run to execute

The runtime values {"a":true,"b":false,"c":true} are only assignable because the compiler resolved each conditional to that exact literal — proof that IsString<'hello'> and IsString<string> both took the true branch while IsString<number> took the false branch.