0
0
Typescriptprogramming~5 mins

Multiple interface extension in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does 'multiple interface extension' mean in TypeScript?
It means one interface can inherit properties and methods from more than one other interface, combining them into a single interface.
Click to reveal answer
beginner
How do you extend multiple interfaces in TypeScript? Show the syntax.
Use the extends keyword followed by a comma-separated list of interfaces. Example:<br>
interface A { a: number; }
interface B { b: string; }
interface C extends A, B { c: boolean; }
Click to reveal answer
intermediate
Can a class implement an interface that extends multiple interfaces?
Yes. When a class implements such an interface, it must provide all properties and methods from all the extended interfaces.
Click to reveal answer
advanced
What happens if two extended interfaces have properties with the same name but different types?
TypeScript will raise an error because the property types conflict. The extending interface must resolve the conflict or avoid incompatible overlaps.
Click to reveal answer
beginner
Example: Write interfaces A and B, then interface C that extends both. Add one property to each. What properties does C have?
interface A { x: number; }
interface B { y: string; }
interface C extends A, B { z: boolean; }
<br>Interface C has properties x, y, and z.
Click to reveal answer
How do you extend multiple interfaces in TypeScript?
Ainterface C extends A, B {}
Binterface C implements A, B {}
Cclass C extends A, B {}
Dclass C implements A, B {}
If interface C extends interfaces A and B, which properties must a class implementing C have?
AProperties from A, B, and C
BOnly properties from C
CProperties from A and B only
DNo properties required
What error occurs if two extended interfaces have the same property name but different types?
ANo error, TypeScript merges types
BType conflict error
CRuntime error only
DProperty is ignored
Which keyword is used by a class to follow an interface?
Ainherits
Bextends
Cimplements
Duses
Can interfaces extend more than two interfaces?
AOnly one interface allowed
BNo, only two interfaces max
CDepends on TypeScript version
DYes, any number separated by commas
Explain how multiple interface extension works in TypeScript and why it is useful.
Think about how you can combine different sets of properties into one interface.
You got /4 concepts.
    Describe what happens when a class implements an interface that extends multiple interfaces.
    Remember the class must fulfill all contracts from all interfaces.
    You got /3 concepts.