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

I…


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 .withA() .withB() and then .build()?”

Let me make it clear about what this blog is gonna talk about.

  1. Motivation: what is the problem? (in details)
  2. Ideas: what is the possible solution?
  3. Solution: what the final solution looks like?
  4. Next step: what can I make it better?

Alright TS nerdy, let’s solve it together!

Motivation: what is the problem? (in details)

The first step to understand the problem is to consider the…

Kasama Chenkaow

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store