In TypeScript, an interface is a syntactical contract that defines how a class or object should look and behave. In other words, it is a blueprint for objects.
Interfaces define properties, methods, and events, which are the members of the interface. A class or object can implement one or more interfaces to inherit the members of the interface.
A class can implement an interface by using the implements keyword. For example:
class Car implements ICar {
//class definition goes here
}
An interface can extend one or more other interfaces. This is done by using the extends keyword. For example:
interface ICar {
//interface definition goes here
}
interface IConvertible extends ICar {
//interface definition goes here
}
In the above example, the IConvertible
interface inherits all the members of the ICar
interface.