In TypeScript, types can be extended (inherited) using both interface extends and type & type (intersection types). Interfaces can also extend types, and vice versa.
Interfaces use the keyword extends to inherit properties:
interface Animal { name: string; } interface Bird extends Animal { wings: number; }
Types can be combined using &:
type Animal = { name: string }; type Bird = Animal & { wings: number };
Also, an interface can extend another type:
type Base = { id: number }; interface Derived extends Base { description: string; }
Features:
Can a type (type) be extended through an interface or vice versa? What mistake do most people make?
Many believe that only interfaces can extend interfaces, but in fact, an interface can extend a type:
type Basic = { flag: boolean }; interface Extra extends Basic { name: string; }
However, a type cannot extend other types through extends—only through intersection types (&).
Story
Story
Story
The team believed that an interface could not be extended by a type, and to extend common functionality, they rewrote all structures from type to interface, wasting a lot of time and effort—when it was simply possible to extend existing types in a non-standard way.