Conditional Types and infer

Use conditional types and infer to create powerful, reactive type logic that adapts to your code.

We’ve seen how TypeScript can transform types with tools like template literals and mapped types. But now we’re entering a more advanced stage where types can make decisions, extract values, and react conditionally.

This is where conditional types and the infer keyword come into play. They form the core of TypeScript’s type-level logic system. With them, we’re not just defining types—we’re programming with types.

By the end of this lesson, we’ll be able to model advanced transformations, extract inner types, and create utility types comparable to those in TypeScript’s standard library.

Conditional types: Types that make decisions

Sometimes we want types that behave differently depending on their input—types that can ask questions and respond with different shapes or values. That’s exactly what conditional types let us do.

Here’s the basic structure: