What is the difference between interface and type in TypeScript?
Both describe the shape of data. An interface describes objects and can be extended or merged; a type alias can name any type, including unions, tuples and primitives.
Explain it simply
An interface is like a form template for an object: "a User must have a name and an email". A type alias is a nickname you can give to any kind of type: an object, a union like "small" | "large", a tuple, or even a plain string. For everyday object shapes, both work almost the same way.
Example
// Interface: good for object shapes and public APIs
interface User {
id: number;
name: string;
}
interface Admin extends User {
permissions: string[];
}
// Type alias: can also name unions and tuples
type Status = "active" | "blocked";
type Point = [number, number];
type AdminUser = User & { permissions: string[] };How it works
interfacecan be extended withextendsand can be declared again with the same name; TypeScript merges the declarations ("declaration merging"). Libraries use this so users can add fields.typecannot be re-declared, but it can express unions (A | B), intersections (A & B), mapped types and conditional types.- Error messages for interfaces are often a little easier to read because the interface name is shown.
Real-world use
- Use interfaces for objects, class contracts and library types that others may extend.
- Use type aliases for unions (API states, button variants), tuples, function types and advanced mapped types.
- Many teams pick one style for objects and stick to it; consistency matters more than the choice.
Common mistakes
- Thinking interfaces are "faster" or "better" in every case. For most code there is no practical difference.
- Trying to write a union with an interface. Unions need
type. - Accidentally merging two interfaces with the same name in one file and getting surprising extra fields.
What to say in the interview
"Both interface and type describe shapes, and for plain objects they are mostly interchangeable. Interfaces can be extended and support declaration merging, which is useful for public APIs. Type aliases are more flexible: they can name unions, tuples, primitives and advanced mapped or conditional types. I usually use interfaces for object contracts and type aliases for unions and utility types, and I follow the team's convention."
Follow-up questions
- What is declaration merging and when is it useful?
- How do you extend a type alias?
- Can a class implement a type alias?