Typescript Intersection and Union Types Combined

Sterling Cobb
1 min readFeb 21, 2019

Today I learned about intersection and union types in Typescript.

If you’re using Typescript, you probably know about union types | and intersection types &

I was doing a code review today and saw something interesting. I saw this (because this is a private repo I’ve change some of the variable names)

export type Example = {
otherPropId: 'start'
propId: string
mode: Mode
x: number
y: number
} & (
| {
shape: 'circle'
r: number
}
| {
shape: 'rect'
w…

--

--