How do you extend interfaces in TypeScript?

Beginner

Answer

Use the extends keyword to inherit properties from other interfaces:

interface Shape {
  color: string;
}

interface Circle extends Shape {
  radius: number;
}

interface Rectangle extends Shape {
  width: number;
  height: number;
}

// Multiple inheritance
interface TimestampedShape extends Shape, Timestamped {
  area: number;
}

interface Timestamped {
  createdAt: Date;
  updatedAt: Date;
}