0
0
Typescriptprogramming~5 mins

Extending interfaces in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does it mean to extend an interface in TypeScript?
Extending an interface means creating a new interface that inherits properties and methods from an existing interface, allowing reuse and addition of new members.
Click to reveal answer
intermediate
How do you extend multiple interfaces in TypeScript?
You list multiple interfaces separated by commas after the extends keyword, like interface NewInterface extends Interface1, Interface2 {}.
Click to reveal answer
intermediate
Can an interface extend a class in TypeScript?
Yes, an interface can extend a class, inheriting its members but without implementation, allowing the interface to describe the shape of the class.
Click to reveal answer
advanced
What happens if an extending interface redeclares a property from the base interface with a different type?
TypeScript will raise an error if the property types are incompatible, because the extending interface must be compatible with the base interface.
Click to reveal answer
beginner
Show a simple example of extending an interface with one additional property.
Example:<br>
interface Animal {
  name: string;
}
interface Dog extends Animal {
  breed: string;
}
Click to reveal answer
Which keyword is used to extend an interface in TypeScript?
Aimplements
Bextends
Cinherits
DextendsInterface
Can an interface extend more than one interface?
ANo, only one interface can be extended
BYes, but only two interfaces
CNo, interfaces cannot extend other interfaces
DYes, by listing them separated by commas
What is the result if an extending interface changes the type of a property from the base interface incompatibly?
ATypeScript throws a type compatibility error
BTypeScript allows it without errors
CThe base interface is changed automatically
DThe property is ignored
Which of the following is a valid way to extend interfaces?
Ainterface A extends B implements C {}
Binterface A implements B, C {}
Cinterface A extends B, C {}
Dinterface A inherits B, C {}
Can an interface extend a class in TypeScript?
AYes, interfaces can extend classes
BNo, interfaces cannot extend classes
COnly abstract classes can be extended by interfaces
DOnly classes with no constructor can be extended
Explain how extending interfaces helps in organizing and reusing code in TypeScript.
Think about how you can build on existing blueprints without rewriting everything.
You got /4 concepts.
    Describe the syntax and rules for extending multiple interfaces in TypeScript.
    Focus on how to list interfaces and what TypeScript expects.
    You got /4 concepts.