Introduction
Sometimes you want to create a new interface that combines properties from several other interfaces. This helps keep your code organized and reusable.
interface NewInterface extends Interface1, Interface2, Interface3 { // additional properties if needed }
interface Animal {
name: string;
}
interface CanRun {
speed: number;
}
interface Dog extends Animal, CanRun {
breed: string;
}interface A {
a: number;
}
interface B {
b: string;
}
interface C extends A, B {}interface Person {
name: string;
}
interface Worker {
job: string;
}
interface Employee extends Person, Worker {
salary: number;
}
const emp: Employee = {
name: "Alice",
job: "Developer",
salary: 50000
};
console.log(`Name: ${emp.name}`);
console.log(`Job: ${emp.job}`);
console.log(`Salary: $${emp.salary}`);interface C extends A, B mean in TypeScript?A and B in TypeScript?extends followed by comma-separated interfaces.interface C extends A, B {}. Others are invalid syntax.interface A { x: number; }
interface B { y: string; }
interface C extends A, B { z: boolean; }
const obj: C = { x: 10, y: "hello", z: true };obj?interface A { a: number; }
interface B { b: string; }
interface C extends A, B {}
const obj: C = { a: 5 };interface Name { first: string; last: string; }
interface Contact { email: string; phone: string; }
interface Employee extends Name, Contact { id: number; }Employee?Pass the test and this pattern moves unknown