Skip to main content

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 }; // Error

But 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 }; // Works

So 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 }; // Works

But 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 types

Summary

OptionCan it inherit?ExampleAlternative
type → interfaceNo, not directlytype B extends A (error)type B = A & { ... } (works)
interface → typeYes, if type is an objectinterface B extends A {} (works)-

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.