Recall & Review
beginner
What does an intersection type do in TypeScript?
An intersection type combines multiple types into one. The new type has all properties and methods from each combined type.
Click to reveal answer
beginner
How do you write an intersection type in TypeScript?
Use the & symbol between types. For example:
type A = B & C; means A has all properties of B and C.Click to reveal answer
intermediate
What happens if two intersected types have properties with the same name but different types?
TypeScript requires the property to satisfy both types. If they conflict, the intersection becomes impossible to satisfy and causes an error or results in the never type.
Click to reveal answer
beginner
Example: What properties does this type have?<br>
type A = {name: string};<br>type B = {age: number};<br>type C = A & B;Type C has both
name (string) and age (number) properties. It combines all properties from A and B.Click to reveal answer
intermediate
Can intersection types combine primitive types like
string & number?No. Intersection of incompatible primitive types like
string & number results in never, meaning no value can satisfy both.Click to reveal answer
What symbol is used to create an intersection type in TypeScript?
✗ Incorrect
The & symbol combines types into an intersection type.
If
type A = {x: number} and type B = {y: string}, what properties does A & B have?✗ Incorrect
Intersection combines all properties, so it has both x and y.
What happens if two intersected types have the same property name but different types?
✗ Incorrect
Conflicting property types cause an error or never type.
What is the result of
string & number in TypeScript?✗ Incorrect
Intersection of incompatible primitives results in never.
Which of these is a valid intersection type?
✗ Incorrect
Only & creates intersection types.
Explain in your own words how intersection types combine multiple types in TypeScript.
Think about how two sets of properties join together.
You got /4 concepts.
Describe what happens when two intersected types have the same property name but different types.
Consider if a property must be both a string and a number at the same time.
You got /3 concepts.