Hello everyone, today I’m going to talk some basics about the union types and integration types in Typescript, if you feel confident about them already please feel free to skip my blog.
I’m not gonna talk about how to use them or those kind of stuffs since the Typescript Handbook is much better place to go for
But I would like to try answering this blog’s title question instead!
Take a look at this code below
You can see that the
union type (AorB) intersects properties from
type A and
type B while
intersection type (AandB) unions them
Recently I needed to build a little typescript library in my work, the team came up with
builder-pattern idea which also brought a simple question like
“How do we get the correct type after we call
.withB() and then
Let me make it clear about what this blog is gonna talk about.
Alright TS nerdy, let’s solve it together!
The first step to understand the problem is to consider the…