Avoid Switch-Case Chaos: Harnessing Strategy Pattern and Union Types in TypeScript

Rico Fritzsche
Level Up Coding
Published in
6 min readJun 21, 2023

--

Remember last time we had a chat about Martin Fowler’s Domain Logic Patterns? We found out how the Transaction Script and Domain Model each have their special perks, and how knowing when to use them can really level up our coding projects.

Well, today we’re diving back into that coding toolbox and dusting off another gem: the Strategy Pattern. We’re also going to spotlight a feature in TypeScript that doesn’t always get the attention it deserves: Union Types. When we bring these two…

--

--

Entrepreneur, Coder & Writer | Smart API Solutions | Proven Expertise in Domain-Driven Design, CQRS/ES & Event Storming. Website: https://ricofritzsche.me