TypeScript Interfaces vs Types
Advertisement
Ad
The Short Answer
Both interface and type describe the shape of data. For object shapes they are almost interchangeable. Use interface for objects/classes, and type for unions, primitives, and tuples.
Defining an Object
interface User {
id: number;
name: string;
}
type UserT = {
id: number;
name: string;
};
What Only "type" Can Do
// Union types
type Status = "active" | "inactive" | "banned";
// Primitive alias
type ID = string | number;
// Tuple
type Point = [number, number];
What Interfaces Do Better
// Declaration merging — two interfaces with the same name combine
interface Window { customProp: string; }
interface Window { anotherProp: number; }
// Both props now exist on Window
// Extending
interface Admin extends User {
role: string;
}
Comparison Table
| Feature | interface | type |
|---|---|---|
| Object shapes | ✅ | ✅ |
| Unions | ❌ | ✅ |
| Tuples | ❌ | ✅ |
| Declaration merging | ✅ | ❌ |
| extends / implements | ✅ | via & |
FAQs
Which should I default to?
A common convention: interface for public API object shapes, type for everything else. Consistency matters more than the choice.
Can they reference each other?
Yes — an interface can extend a type and vice versa. More in our TypeScript section.
