Type and interface inheritance
1. Can a type inherit from an interface?
Not directly.
Types (type) do not support the extends keyword at creation, that is, you cannot write this:
javascript
interface A {
name: string;
}
type B extends A = { age: number }; // ErrorBut you can combine a type and an interface through an intersection (&), which is essentially equivalent to inheritance:
javascript
interface A {
name: string;
}
type B = A & { age: number }; // WorksSo a type does not "inherit" an interface, but it can extend it using &.
2. Can an interface inherit from a type?
Yes, if the type is an object structure.
TypeScript lets an interface inherit from a type through extends, but only if the type describes an object (not a primitive, a union, etc.):
javascript
type A = { name: string };
interface B extends A {
age: number;
}
const obj: B = { name: "Tim", age: 25 }; // WorksBut if the type is not an object (for example, a union or a primitive), there will be an error:
javascript
type C = string | number;
interface D extends C {} // Error: an interface can only inherit object typesSummary
| Option | Can it inherit? | Example | Alternative |
|---|---|---|---|
| type → interface | No, not directly | type B extends A (error) | type B = A & { ... } (works) |
| interface → type | Yes, if type is an object | interface B extends A {} (works) | - |
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.