![]() |
VOOZH | about |
In TypeScript, extending an interface means one interface can inherit the properties and methods of another. Similarly, an interface can also extend a class, reusing its structure.
Syntax:
This is the syntax for creating a class. We may use the below syntax for creating a class in TypeScript:
class class_name {
...
}This is the syntax for creating an interface. We may use the below syntax for creating an interface in TypeScript:
interface interface_name {
...
}In TypeScript, an interface can extend a class. This means the interface inherits the class’s properties and methods . Any class implementing that interface must provide the method definitions.
Now let's understand this with the help of example:
Output:
GeeksforGeeksIn this example:
In TypeScript, a class can implement multiple interfaces. This allows us to combine different contracts (sets of properties and methods) into one class, making it more flexible and reusable.
Now let's understand this with the help of example:
Output:
1 - Apple
2 - BananaIn this example: