How to Extend an Interface from a class in TypeScript ?
Last Updated :
12 Sep, 2025
In TypeScript, extending an interface means one interface can inherit the properties and methods of another. Similarly, an interface can also extend a class, reusing its structure.
Syntax:
This is the syntax for creating a class. We may use the below syntax for creating a class in TypeScript:
class class_name {
...
}This is the syntax for creating an interface. We may use the below syntax for creating an interface in TypeScript:
interface interface_name {
...
}Interface Extending a Class
In TypeScript, an interface can extend a class. This means the interface inherits the class’s properties and methods . Any class implementing that interface must provide the method definitions.
Now let's understand this with the help of example:
JavaScript
class Person {
public name: string;
}
interface Details extends Person {
details(): void;
}
class Person_Details extends Person implements Details {
details(): void {
this.name = "GeeksforGeeks";
console.log(this.name);
}
}
let object = new Person_Details();
object.details();
Output:
GeeksforGeeks
In this example:
- A class is defined with some properties.
- An interface extends that class and declares a method.
- A new class extends the base class and implements the interface, providing the actual method definition.
- Finally, we create an object and call the method.
Multiple Interfaces with a Class
In TypeScript, a class can implement multiple interfaces. This allows us to combine different contracts (sets of properties and methods) into one class, making it more flexible and reusable.
Now let's understand this with the help of example:
JavaScript
class Student {
public id: number;
public name: string;
}
interface Student_1 extends Student {
student1_details(): void;
}
interface Student_2 extends Student {
student2_details(): void;
}
class Student_Details extends Student implements Student_1, Student_2 {
student1_details(): void {
this.name = "Apple";
this.id = 1;
console.log(this.id + " - " + this.name);
}
student2_details(): void {
this.name = "Banana";
this.id = 2;
console.log(this.id + " - " + this.name);
}
}
let student_object = new Student_Details();
student_object.student1_details();
student_object.student2_details();
Output:
1 - Apple
2 - Banana
In this example:
- A parent class is created with variable declarations.
- Two interfaces are defined, each declaring its own method.
- A derived class extends the parent class and implements both interfaces.
- An object is created to call all the implemented methods.
Explore
TypeScript Basics
TypeScript primitive types
TypeScript Object types
TypeScript other types
TypeScript combining types
TypeScript Assertions
TypeScript Functions
TypeScript interfaces and aliases
TypeScript classes
TypeScript modules