An intersection type combines multiple types into one. It means a value must satisfy all the combined types at the same time.
Click to reveal answer
beginner
How do you write an intersection type in TypeScript?
Use the ampersand (&) symbol between types. For example: type A = Type1 & Type2;
Click to reveal answer
intermediate
What happens if two intersected types have conflicting properties?
TypeScript will require the property to satisfy both types. If conflicts can't be resolved, it causes a type error.
Click to reveal answer
beginner
Example: What does this type mean? type Person = { name: string } & { age: number };
It means a Person must have both a name (string) and an age (number).
Click to reveal answer
intermediate
Can intersection types combine interfaces and types?
Yes, you can intersect interfaces and type aliases together using & to create a new combined type.
Click to reveal answer
Which symbol is used for intersection types in TypeScript?
A|
B&
C+
D*
✗ Incorrect
The ampersand (&) symbol is used to combine types into an intersection type.
What does this intersection type require? {a: number} & {b: string}
AAn object with both a and b
BAn object with a or b but not both
CAn object with either a or b
DAn object with neither a nor b
✗ Incorrect
Intersection means the object must have both properties a and b.
Can intersection types be used to combine primitive types like string & number?
AYes, it creates a union
BNo, it creates an array
CYes, it creates a tuple
DNo, it results in never type
✗ Incorrect
Intersecting incompatible primitive types like string & number results in the never type, meaning no value can satisfy both.
If two intersected types have the same property with different types, what happens?
ATypeScript picks the first type
BTypeScript picks the second type
CTypeScript throws a type error
DTypeScript ignores the property
✗ Incorrect
Conflicting property types in intersection cause a type error because no value can satisfy both.
Which of these is a valid intersection type?
Atype T = {x: number} & {y: string};
Btype T = {x: number} | {y: string};
Ctype T = {x: number} + {y: string};
Dtype T = {x: number} - {y: string};
✗ Incorrect
Only the ampersand (&) is valid for intersection types.
Explain in your own words what an intersection type is and how it is used in TypeScript.
Think about how two sets overlap and what belongs to both.
You got /3 concepts.
Describe a situation where using an intersection type would be helpful in a program.
Imagine you want an object that has features from two different things.
You got /3 concepts.
Practice
(1/5)
1.
What does the intersection type type AB = A & B; mean in TypeScript?
easy
A. It creates a new type that excludes properties from A and B.
B. It creates a union type that can be either A or B.
C. It combines types A and B so the result has all properties from both.
D. It merges A and B but only keeps properties common to both.
Solution
Step 1: Understand intersection operator &
The & symbol in TypeScript creates an intersection type combining all properties from both types.
Step 2: Compare with union and other operations
Unlike union (|), intersection requires all properties from both types to be present.
Final Answer:
It combines types A and B so the result has all properties from both. -> Option C
Quick Check:
Intersection = all properties combined [OK]
Hint: Intersection uses & to combine all properties [OK]
Common Mistakes:
Confusing intersection (&) with union (|)
Thinking intersection keeps only common properties
Assuming intersection excludes properties
2.
Which of the following is the correct syntax to define an intersection type of Person and Employee?
easy
A. type Staff = Person | Employee;
B. type Staff = Person & Employee;
C. type Staff = Person, Employee;
D. type Staff = Person && Employee;
Solution
Step 1: Recall intersection syntax
Intersection types use the & symbol to combine types.
Step 2: Check each option
type Staff = Person & Employee; uses & correctly for intersection. type Staff = Person | Employee; uses union |. Comma is invalid syntax. && is a logical operator, not type syntax.
Final Answer:
type Staff = Person & Employee; -> Option B
Quick Check:
Intersection syntax = & [OK]
Hint: Use & to join types for intersection [OK]
Common Mistakes:
Using | instead of & for intersection
Using commas or && which are invalid
Confusing logical operators with type operators
3.
What is the type of variable user after this code?
type A = { name: string };
type B = { age: number };
const user: A & B = { name: "Alice", age: 30 };
medium
A. Error: incompatible types
B. { age: number }
C. { name: string }
D. { name: string; age: number }
Solution
Step 1: Understand intersection type A & B
The type A & B combines properties from both A and B, so it must have name and age.
Step 2: Check the assigned object
The object has both name: "Alice" and age: 30, matching the intersection type.
Final Answer:
{ name: string; age: number } -> Option D
Quick Check:
Intersection type = combined properties [OK]
Hint: Intersection type has all properties combined [OK]
Common Mistakes:
Thinking intersection keeps only one type's properties
Expecting a type error when all properties are present
Confusing intersection with union
4.
Identify the error in this TypeScript code using intersection types:
type X = { a: number };
type Y = { b: string };
const obj: X & Y = { a: 5 };
medium
A. Missing property 'b' from type Y in the object.
B. Incorrect use of & operator for intersection.
C. Property 'a' should be a string, not number.
D. Object should use union type | instead of &.
Solution
Step 1: Check required properties for intersection X & Y
The intersection requires all properties from both X and Y, so both a and b must be present.
Step 2: Inspect the object literal
The object only has a: 5 but is missing b, causing a type error.
Final Answer:
Missing property 'b' from type Y in the object. -> Option A
Quick Check:
Intersection requires all properties present [OK]
Hint: Intersection needs all properties present in object [OK]
Common Mistakes:
Forgetting to include all properties in intersection
Confusing intersection with union allowing partial properties
Misusing & operator syntax
5.
Given these types, which is the correct way to define a variable fullInfo that must have all properties from Person, Employee, and Contact?
type Person = { name: string };
type Employee = { id: number };
type Contact = { email: string };
hard
A. const fullInfo: Person & Employee & Contact = { name: "Bob", id: 1, email: "bob@example.com" };
B. const fullInfo: Person | Employee | Contact = { name: "Bob", id: 1, email: "bob@example.com" };
C. const fullInfo: Person & Employee | Contact = { name: "Bob", id: 1, email: "bob@example.com" };
D. const fullInfo: Person | Employee & Contact = { name: "Bob", id: 1, email: "bob@example.com" };
Solution
Step 1: Understand combining multiple types
To require all properties from Person, Employee, and Contact, use intersection of all three types with &.
Step 2: Analyze each option
const fullInfo: Person & Employee & Contact = { name: "Bob", id: 1, email: "bob@example.com" }; correctly uses Person & Employee & Contact. const fullInfo: Person | Employee | Contact = { name: "Bob", id: 1, email: "bob@example.com" }; uses union which allows any one type only. Mixing union and intersection incorrectly.
Final Answer:
const fullInfo: Person & Employee & Contact = { name: "Bob", id: 1, email: "bob@example.com" }; -> Option A
Quick Check:
All properties require intersection & [OK]
Hint: Use & to combine multiple types for all properties [OK]
Common Mistakes:
Using union | instead of intersection & for all properties
Mixing union and intersection without parentheses
Assuming union requires all properties
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.