Interfaces
An interface is a way to define a contract for the shape of an object. It specifies the names and types of properties and methods that an object must have to be considered an instance of that interface.
Interfaces can be used to specify the shape of objects, define the structure of classes, and describe the signatures of functions.
Example:
1 |
|
Interfaces are compile-time constructs, meaning that the TypeScript compiler does not generate any JavaScript code for interfaces at runtime.
Best Practice:
Interfaces are considered to be the better version of “types” as they have improved performance over intersection types (source), allow declaration merging and support module augmentation.