DEV Community

Cover image for Do Union and Intersection Types Slow Down Your Build?

Do Union and Intersection Types Slow Down Your Build?

Steve Belovarich
full stack web engineer, creative coder, teacher, cultural critic and indie music fan.
・1 min read

I've been using unions and intersection types as outlined here on but the compile step with tsc keeps getting longer the more I use this pattern, at least it seems that way.

I've observed at least one open source library making heavy usage of unions that slowed down the build to a crawl when destructuring an Object mapped to one of these type unions. I won't know for sure if they are to blame for slow build times unless I rewrite a bunch of type definitions, so I'm wondering if anyone else has encountered slow builds because of using unions and intersection types with TypeScript?

Are there rules to using this pattern responsibly that I'm missing?

The answer may prompt a rewrite of the type definitions. At the expense of complexity / code duplication, I could gain faster builds. That matters to me, because who wants to sit around waiting for TypeScript to compile? I know I don't.

Discussion (1)

steveblue profile image
Forem Open with the Forem app