

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
An intersection type combines multiple types into one with the & operator. The resulting intersection type satisfies all the component types simultaneously.
type IndividualContributor = {
id: number;
name: string;
tasks: string[];
};
type Manager = {
directReports: number[];
};
type GoodManager = IndividualContributor & Manager;
const hunter: GoodManager = {
id: 1,
name: "Hunter Backmann",
tasks: ["Fixing Lane's B*llsh*t code", "Vibe Coding"],
directReports: [2, 3, 4],
};
A GoodManager must have all the properties of both an IndividualContributor and a Manager. When you intersect object types, TypeScript merges their properties:
type Point2D = {
x: number;
y: number;
};
type Point3D = Point2D & {
z: number;
};
// Equivalent to:
// type Point3D = {
// x: number;
// y: number;
// z: number;
// };
Create and export new TextBot and VoiceBot types. They should each intersect with the existing SupportBot type but have the following additional properties:
TextBot:
messageLog - an array of stringssendMessage - a function that takes a message string and returns a stringVoiceBot
callLog - an array of stringsphoneNumber - a stringdialNumber - a function that takes a phoneNumber string and returns a string