

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Intersections of Types
incomplete
2: The Never Type
incomplete
3: Intersecting Incompatible Types
incomplete
4: Intersections vs. Unions
incomplete
5: Super Set Unions
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
What happens when we intersect types with overlapping properties?
type Saiyan = {
name: string;
powerLevel: number;
};
type Human = {
name: string;
age: number;
};
type SaiyanHuman = Saiyan & Human;
We get this SaiyanHuman type that's the equivalent of:
type SaiyanHuman = {
name: string;
powerLevel: number;
age: number;
};
It merges the properties of both Saiyan and Human, and because name overlaps, it safely combines the two types and appears once in the resulting type.
What happens if the name field were incompatible types? For example:
type Saiyan = {
name: "goku" | "vegeta";
powerLevel: number;
};
type Human = {
name: "krillin" | "yamcha";
age: number;
};
type SaiyanHuman = Saiyan & Human;
Now the name property can't possibly satisfy both! Humans must be krillin or yamcha, and Saiyans must be goku or vegeta. So, the name property in SaiyanHuman becomes never, which in turn makes the entire SaiyanHuman type never.
// Type '{}' is not assignable to type 'never'
const theLaneagen: SaiyanHuman = {};
It's TypeScript saying, "Hey, the SaiyanHuman type is impossible, do something else." Most of the time, the solution here is to redesign your types to avoid incompatible intersections and make sense.
Support.ai enriches customer tickets with two types of metadata:
These two types were combined using an intersection to create the TicketMetadata type – but there's a bug! Hover over TicketMetadata and notice that it's never due to an incompatible intersection.
getReviewMethod should return "manual_review" if any of the following are true:
"phone"Otherwise, it should return "auto_process".