Interface vs Type Alias
7 min read
Interface vs Type Alias
Both interface and type can describe object shapes, and for most use-cases they are interchangeable. The choice often comes down to team convention, but there are real differences.
interfacesupports declaration merging;typedoes nottypecan alias unions, intersections, tuples, and primitives;interfacecannotinterfaceextends with theextendskeyword;typecomposes with&- Error messages for
interfaceviolations are sometimes clearer - Both compile away to zero runtime cost
ts
// Only possible with type:
type StringOrNumber = string | number;
type Pair = [string, number];
// Only possible with interface:
interface Logger {
log(msg: string): void;
}
interface Logger {
warn(msg: string): void; // merged!
}
// Composition comparison:
interface A { a: number; }
interface B extends A { b: string; }
type C = { a: number };
type D = C & { b: string };A common convention: use interface for public APIs and class contracts; use type for unions, utility compositions, and local helper types. Pick one and stay consistent within a codebase.
Ready to test yourself?
Practice TypeScript— quiz & coding exercises