An interface provides us with a mechanism to define what properties and methods an object must implement, and is, therefore, a way of defining a custom type. We have already explored the TypeScript syntax for strongly typing a variable to one of the basic types, such as a string or number. Using this syntax, we can also strongly type a variable to be of a custom type, or more correctly, an interface type. This means that the variable must have the same properties as described in the interface. If an object adheres to an interface, it is said that the object implements the interface. Interfaces are defined by using the interface keyword.
To illustrate the concept of interfaces, consider the following code:
interface IComplexType { id: number; name: string; }
We start with an interface named IComplexType that has an id and a name property. The id property...