Syntax
interface Name { }
type Name = { };Examples
Declaration Merging - interface Only
A capability unique to interfaces, often used to extend third-party library types.
interface Window {
myCustomProperty: string;
}
interface Window {
anotherProperty: number;
}
// TypeScript automatically merges both declarations -
// Window now has BOTH myCustomProperty and anotherProperty
// This is impossible with type - a duplicate type alias name is a compile errorWhat type Can Do That interface Cannot
Unions, tuples, and primitive aliases are exclusive to type.
type Status = "pending" | "active"; // interface cannot express a union like this
type Point = [number, number]; // interface cannot express a tuple like this
type ID = string | number; // interface cannot alias a primitive unionBest practices
- For plain object shapes, either works - many teams default to interface for public APIs and type for everything else, but consistency matters more than the specific choice
- Use interface specifically when you need declaration merging, such as augmenting a type from a third-party library
- Use type when you need a union, tuple, or an alias for a primitive - interface simply cannot express these
- Within a single codebase, pick one convention for object shapes and apply it consistently, rather than mixing arbitrarily
Runtime & versions
Compiled to JavaScript. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
TypeScript Handbook