6.6 The Pitfalls of Intersecting Primitives
Alright, let’s talk about one of the first places TypeScript’s type system will gleefully smack you in the face: intersecting primitives. You’ve probably seen the & operator and thought, “Ah, union is OR, so intersection must be AND. I’ll take this string and this number and get a type that is both a string AND a number! Checkmate, type system!” Let me stop you right there. I need you to imagine the TypeScript compiler, a profoundly logical but utterly humorless entity, staring at you blankly. It’s not going to create a new quantum value that is simultaneously a string and a number. That’s not how our universe works, and it’s certainly not how TypeScript’s type algebra works.