JS Built-ins
TypeScriptbeginner

Interface β€” Extends

πŸ“– Usage Example
interface Animal { name: string }
interface Dog extends Animal { breed: string }
const d: Dog = { name: 'Rex', breed: 'Labrador' }

Interface extends inherits all properties from a base interface and adds new ones.

Interface Extends

An interface can extend another to inherit its properties, then add more.

Challenge: Implement createDog(name, breed) returning a Dog that extends Animal.

createDog('Rex', 'Lab')  // β†’ { name: 'Rex', breed: 'Lab', sound: 'woof' }
πŸ’‘ Hints (1)
  • β€’ The Dog interface inherits name and sound from Animal.