Junior — Middle
Is it possible in TypeScript to create interfaces that inherit from each other?
sobes.tech AI
Answer from AI
Yes, in TypeScript, interfaces can inherit from each other using the extends keyword. This allows creating more specialized interfaces based on basic ones.
Example:
interface Animal {
name: string;
}
interface Dog extends Animal {
breed: string;
}
const myDog: Dog = {
name: "Buddy",
breed: "Labrador"
};
In this example, the Dog interface inherits the name property from the Animal interface and adds its own breed property.