When Conditionals Resolve
You'll learn: TypeScript evaluates conditional types at different times depending on whether they involve known or generic types.
The Core Idea
Not all conditional types are evaluated immediately. TypeScript distinguishes between:
- Immediate resolution — when all types involved are concrete/known
- Deferred resolution — when type parameters are involved and not yet known
Think of it like a math expression: 2 + 3 can be calculated right away, but x + 3 must wait until you know what x is.
Immediate Resolution
When TypeScript has all the information, it resolves conditionals instantly:
type IsString = string extends string ? true : false;
// Resolves immediately to: true
type IsNumber = "hello" extends number ? true : false;
// Resolves immediately to: false
TypeScript knows all the types involved, so it can give you the answer right away.
Deferred Resolution
When a conditional type involves unresolved type parameters, TypeScript must wait:
type WaitForIt<T> = T extends string ? true : false;
// Not resolved yet — T is still unknown
type Mystery = WaitForIt<never>; // Deferred...
type Answer = WaitForIt<"hello">; // Now resolves to true
Until you supply a concrete type for T, TypeScript can't decide which branch to take. The conditional stays "suspended" in the type system.
Why This Matters
Understanding resolution timing helps you predict when TypeScript can infer types and when it needs more information. Deferred conditionals enable powerful patterns like filtering, mapping, and transforming types based on runtime arguments—but they can also lead to confusing error messages if you forget the condition hasn't resolved yet.
Key Takeaway: Conditional types with concrete inputs resolve immediately; those with type parameters defer until the parameter is known.