How intersection combines types
📖 Scenario: Imagine you are creating a profile system where a user can be both a Student and an Employee. You want to combine these two roles into one type that has all properties from both.
🎯 Goal: You will create two types, then combine them using an intersection type. Finally, you will create a variable of the combined type and print its properties.
📋 What You'll Learn
Create a type called
Student with properties name (string) and grade (number).Create a type called
Employee with properties name (string) and salary (number).Create an intersection type called
StudentEmployee that combines Student and Employee.Create a variable called
person of type StudentEmployee with all required properties.Print the
name, grade, and salary of person.💡 Why This Matters
🌍 Real World
Combining multiple roles or features into one object is common in user profiles, permissions, and settings in real applications.
💼 Career
Understanding intersection types helps you write flexible and safe TypeScript code, which is valuable for frontend and backend development jobs.
Progress0 / 4 steps