Extending Interfaces

Extending Interfaces
πŸ‘¨β€πŸ’Ό Interfaces can extend other interfaces, inheriting their properties. This is cleaner than copying properties manually.
interface Animal {
	name: string
}

interface Dog extends Animal {
	breed: string
}

// Dog has both name and breed
const dog: Dog = { name: 'Rex', breed: 'German Shepherd' }
🐨 Open
index.ts
and:
  1. Create a Timestamps interface with createdAt: Date and updatedAt: Date
  2. Create an Entity interface that extends Timestamps and adds id: string
  3. Create User and Product interfaces that extend Entity with their own fields (name/email and name/price)
  4. Create an AuditLog interface that extends Timestamps (not Entity) with action: string and userId: string
  5. Create sample user, product, log, and entity values and export them by name

Completion criteria

  • Named exports: user, product, log, entity
  • user / product include id, timestamps (Date), and their own fields
  • log has timestamps plus action / userId (no id required)
  • entity has id plus createdAt / updatedAt as Dates

Please set the playground first

Loading "Extending Interfaces"
Loading "Extending Interfaces"
Login to get access to the exclusive discord channel.
Loading Discord Posts