skip to content
Alvin Lucillo

Inheritance in interfaces

/ 1 min read

💻 Tech

In Typescript, we can make use of inheritance concept with extends. This essentially allows an interface to reuse the existing properties of another interface. In the example below, emp is defined with Employee interface, which inherits the properties of another interface Base.

interface Base {
    id: number;
    name: string;
}

interface Employee extends Base {
    department: string;
}

const emp: Employee = {
id: 1,
name: 'Long Da',
department: 'Zhong Guo'
}

console.log(emp);
/*
{
  department: "Zhong Guo",
  id: 1,
  name: "Long Da"
}
/*