Menu

1 / 2

Conditional Types: When They Earn Their Complexity and When They Don't

DEV Community·Gabriel Anhaia·6 months ago
#02WzBsqc
#case#antipattern#typescript#programming#type
Reading 0:00
15s threshold

Book: The TypeScript Type System — From Generics to DSL-Level Types

Also by me: The TypeScript Library — the 5-book collection

My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools

Me: xgabriel.com | GitHub

A junior on your team opens a PR with a 14-line conditional type at the top of the user service. It widens the return type of a wrapper so callers see a stricter shape. It works. Reviews stall for two days because nobody on the review thread can read it without a whiteboard.

You sit with the type for ten minutes and replace it with a four-line union. The wrapper still works. The reviewers move on.

That is the question every conditional type has to answer: is the structural inference worth what it costs the next reader? Sometimes the answer is yes and the type pays for itself across a hundred call sites. Sometimes the same shape would be a literal union you can read at a glance.

The shape, in one paragraph

A conditional type is T extends X ?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.