Interfaces
What
An interface is a way to define the shape of an object, similar to a type alias. While they are often interchangeable, interfaces have unique capabilities related to inheritance and merging.
How
You define an interface using the interface keyword followed by the structure of the object:
interface Superhero {
name: string;
powers: string[];
isAvenger: boolean;
}
Why
Interfaces are a core part of TypeScript’s object-oriented features. While type is generally more flexible (as it can represent primitives and unions), interface is often preferred for defining public APIs or structures that are meant to be extended by other parts of a system.
Summary
Interfaces provide a robust way to define object contracts, especially in large-scale applications where type inheritance is common.