Course contentsShow
← TypeScript
Lesson 778 of 1,79618. Conditional TypesFree lesson

Readability vs Power Trade-offs

Recognize when conditional types make code harder to understand and when simpler alternatives exist.

Readability vs Power Trade-offs

You'll learn: When conditional types make code harder to understand and when simpler alternatives exist.

Conditional types are one of TypeScript's most powerful features, but with great power comes the risk of writing code that looks like line noise to your teammates (or future you). Just because you can nest five conditional types inside a mapped type doesn't mean you should.

The Complexity Trap

Conditional types let you express incredibly sophisticated type logic, but each layer adds cognitive load. Consider this type:

type Unwrap<T> = T extends Promise<infer U> ? U : T;

This is elegant and readable. But what about:

type DeepUnwrap<T> = T extends Promise<infer U>
  ? U extends Promise<infer V>
    ? V extends Promise<infer W>
      ? W
      : V
    : U
  : T;

Technically impressive? Yes. Easy to debug or maintain? Absolutely not.

When Simpler Alternatives Exist

Often a union type, function overload, or even a generic constraint can express the same constraint more clearly:

Conditional type approach:

type Result<T> = T extends string ? string[] : number[];

Union approach:

type Result = string[] | number[];

If you're not actually using the conditional logic to transform types, the simpler union is clearer.

Key Takeaway: Use conditional types when their power genuinely solves a problem that simpler features can't, but always ask: "Will someone reading this in six months understand it?" Favor readability unless the complexity is truly necessary.