TypeScript Interfaces vs Types
Short answer: for describing the shape of objects, interface and type are almost interchangeable. Use interface for object shapes and class contracts that may be extended, and use type when you need unions, intersections, tuples, mapped or conditional types. Pick one convention per project and stay consistent.
Basic syntax
interface User {
id: number;
name: string;
}
type UserType = {
id: number;
name: string;
};
Both describe the same object shape, and a value of either type can be used wherever the other is expected.
Extending
// interface: extends
interface Admin extends User {
permissions: string[];
}
// type: intersection
type AdminType = UserType & {
permissions: string[];
};
Both achieve the same result. Interfaces report conflicting property types as an error at the point of extension, which can make mistakes easier to spot.
Declaration merging (interfaces only)
Declaring an interface twice merges the two declarations:
interface Settings { theme: string }
interface Settings { language: string }
const s: Settings = { theme: "dark", language: "en" }; // both fields required
A type alias cannot be declared twice; it gives an error. Merging is useful for augmenting library types, such as adding a field to an Express request.
What only type can do
// Union
type Id = string | number;
// Tuple
type Point = [number, number];
// Primitive alias
type Email = string;
// Mapped type
type ReadOnly<T> = { readonly [K in keyof T]: T[K] };
// Conditional type
type IsString<T> = T extends string ? true : false;
Unions and mapped or conditional types are the main reason to choose type. An interface can only describe an object-like shape (including functions and classes).
Classes
interface Printable { print(): void }
class Report implements Printable {
print() { console.log("Report"); }
}
A class can implements either an interface or a type alias that describes an object, but interfaces are the traditional choice.
Comparison table
| Feature | interface | type |
|---|---|---|
| Object shapes | Yes | Yes |
| Extend | extends | Intersection & |
| Declaration merging | Yes | No |
| Union types | No | Yes |
| Tuples and primitives | No (awkward) | Yes |
| Mapped / conditional types | No | Yes |
| Implemented by a class | Yes | Yes (object types) |
A practical rule of thumb
- Public object shapes, props and class contracts:
interface. - Unions, tuples, utility or computed types:
type. - Following an existing codebase: match what it already does.
Performance differences are negligible for most projects. If you are new to the language, start with what TypeScript is, and then explore generics and utility types.
FAQs
Which is better, interface or type?
Neither is universally better. Use interface for extendable object shapes and type for everything that needs unions or advanced type features.
Can an interface extend a type?
Yes, as long as the type describes an object shape that is statically known.
Why does the TypeScript handbook mention interfaces first?
Interfaces map well to object-oriented patterns and produce clearer error messages in many cases, but the handbook states both are fine.
Can I convert one to the other?
Yes, for plain object shapes. You lose merging when going from interface to type, and unions when going the other way.
