BeCuriouzLearn something new every day
type vs interface: Which Should You Reach For?
💡 Use interface for object shapes you may extend or merge; use type alias when you need unions, tuples, or anything that isn't a plain object.
TypeScript gives you two ways to name the shape of an object: an interface and a type alias. For a basic object, they look almost identical:
interface User {
name: string;
age: number;
}
type User = {
name: string;
age: number;
};The biggest practical difference is declaration merging. If you declare the same interface twice, TypeScript merges the two into one — a feature libraries use to let you extend existing types. A type alias can't do this: declaring the same name twice is a duplicate identifier error.
interface Box { width: number; }
interface Box { height: number; } // OK — Box now has both
type Cat = { legs: number; };
type Cat = { tail: boolean; }; // Error: Duplicate identifier 'Cat'The flip side: a type alias can name anything, not just object shapes — unions, primitives, tuples, and mapped types. Only type can write type ID = string | number or type Pair = [number, number]. Interfaces are limited to describing object-like structures. A common rule of thumb: reach for interface when defining the shape of an object or class (especially in a public API where merging or extends helps), and reach for type when you need unions, tuples, or other non-object shapes.