Course contentsShow
← TypeScript
Lesson 1694 of 1,79638. Common Patterns and AntipatternsFree lesson

When Simple Types Win

Recognizing situations where explicit unions or basic generics outperform sophisticated abstractions.

When Simple Types Win

You'll learn: How to recognize when a straightforward union or basic generic outperforms sophisticated type-level abstractions.

The Sophistication Trap

After mastering conditional types, mapped types, recursive structures, and template literals, it's tempting to apply these tools everywhere. But TypeScript's most powerful features aren't always your best choice. Simple types often win on readability, maintainability, and compile speed—even when you could solve the problem with something fancier.

The Recognition Pattern

Ask yourself three questions:

1. Can a union solve this?
Before reaching for conditional types to filter or transform, consider whether a simple union of explicit types would be clearer. If you have three known states, writing type Status = "idle" | "loading" | "success" beats a generic string-literal-generating mapped type.

2. Does a basic generic preserve the information you need?
Sometimes <T> is enough. You don't need <T extends SomeConstraint, U = Extract<Keys<T>, ValidKeys>> when <T> with a straightforward return type does the job. Generic constraints are powerful, but each one adds cognitive load.

3. Will future maintainers understand this in 30 seconds?
If your type requires scrolling, nested conditionals, or a mental map of four type parameters, it's probably too clever. The compile-time guarantee you gain might not outweigh the maintenance cost.

Practical Examples

Instead of a recursive conditional type that generates all possible property paths, an explicit tuple like ["user", "address", "street"] might serve your actual use case just fine.

Instead of a complex builder pattern with phantom types tracking state transitions, a simple discriminated union representing each valid state combination works better for most real-world forms.

Instead of variadic tuple gymnastics to type a pipeline, explicit overloads for the 2-3 actual use cases you have keeps your API clear.

The Wisdom

Sophisticated types are tools for sophisticated problems. Most problems aren't sophisticated—they're just slightly flexible. Use the simplest type that captures your actual requirements, not your imagined future requirements.

Key Takeaway: Choose explicit unions and straightforward generics over type-level cleverness unless the complexity genuinely buys you safety or flexibility you'll actually use. Simple types are easier to debug, faster to compile, and kinder to your teammates.