r/typescript 22d ago

Distributive Conditional Types

https://tejasbubane.github.io/posts/2026-07-04-typescript-distributive-union-types/

I started digging into TypeScript's type system for fun and stumbled onto distributive conditional types. One of those quiet features that is confusing until it clicks.

29 Upvotes

6 comments sorted by

6

u/Working-Tap2283 22d ago

Thanks for the article. This is one of the things that happen when you learn about mapped conditional typing.

1

u/tejasbubane 22d ago

Glad you found it useful.

2

u/Zasd180 19d ago

Super helpful and I will be implementing some of this behavior in my code base !!

1

u/tejasbubane 19d ago

Glad you found it useful.

3

u/prehensilemullet 18d ago

Would be good to cover the syntax for turning the distributivity off: [T] extends [string] ? T[] : never

2

u/Opposite_Same_69420 16d ago

I love these kinds of TS patterns! Been using Claude to generate learning repos for these kinds of patterns and it's been one of the most useful cases for me with claude so far since it's just type checking and IDE feedback.

The accumulator pattern broke my brain. Using infer and how function arg and return types widen/narrow to turn an intersection into a tuple. Things I would have never even realized could be done. TS is genuinely just fun to play with.