Unions and Narrowing 28 exercises
explainer

# How Big Can a Union Be?self.__wrap_balancer=(t,e,n)=>{n=n||document.querySelector(`[data-br="\${t}"]`);let o=n.parentElement,r=E=>n.style.maxWidth=E+"px";n.style.maxWidth="";let i=o.clientWidth,s=o.clientHeight,c=i/2,u=i,d;if(i){for(;c+1<u;)d=~~((c+u)/2),r(d),o.clientHeight==s?u=d:c=d;r(u*e+i*(1-e))}};self.__wrap_balancer(":Rhd9j6:",1)

Let's explore the upper limits of union types in TypeScript.

We start with an `Alphabet` type, which is, as the name suggests, a union of all the letters in the alphabet:

`type Alphabet = "a" | "b" | "c" | // etc...`

Using some advanced type syntax, we can create a type that is `T

## Transcript

00:00 How big can a union get in TypeScript? Well, we've got this alphabet type, which is basically a massive union type of all of the letters in the alphabet. So 26 in there. And we've got a type down the bottom here, which is too big. This is using some advanced type syntax to basically create a,

00:18 what it's trying to do is it's creating a string where each of the letters in the alphabet can potentially be in each slot here. So it's like four letters long, each of the ones of the alphabet. And you might think TypeScript will probably be able to handle this. Well, if you think about it, it's like 26 here, times 26, times 26,

00:38 times 26. So 26 to the power of four. And that creates a union type that is too complex to represent. So TypeScript sometimes just sort of like goes, oh, please don't make me do this. Why are you making me do this? Because usually a better way to just represent this is just with a string. You know, you don't need to be too precise here.

00:59 And so there is an upper limit on how big a union can be in TypeScript. And you'll sometimes hit this error, but usually only when you're doing something that you probably shouldn't be doing. Anyway, I thought I'd include this because it's pretty fun.