Course contentsShow
← TypeScript
Lesson 277 of 1,7966. FunctionsFree lesson

Overloads vs Conditional Types

When to use function overloads versus generic conditional return types.

Overloads vs Conditional Types

You'll learn when to choose function overloads versus generic conditional return types for complex function signatures.

The Core Dilemma

Both function overloads and generic conditional types solve the same problem: expressing that a function's return type depends on its input type. But they work differently and shine in different scenarios.

Function overloads are explicit: you list out each signature combination one by one. They're readable and straightforward, but can become verbose with many variations.

Generic conditional types are dynamic: you write a single signature with a type that branches based on generic type parameters. They're powerful and concise, but can be harder to read and understand.

When to Use Overloads

Choose overloads when:

  • You have a small, fixed set of input/output combinations (2-4 variations)
  • The relationship between parameters is complex (not just "if input A, then output B")
  • You want clear, explicit documentation that's easy to read
  • Parameter types change together in specific combinations

Think of overloads as a menu: "If you order this, you get that."

When to Use Conditional Types

Choose conditional types when:

  • The pattern is systematic and predictable ("input type directly determines output type")
  • You have many potential combinations that follow the same rule
  • You're building a generic utility meant to work with any type
  • The logic is simple: "input extends X ? Y : Z"

Think of conditional types as a formula: "Whatever you put in determines what comes out."

Key Takeaway: Use overloads for small, explicit sets of variations; use conditional types for scalable, pattern-based type transformations. Overloads are more readable; conditionals are more powerful.