Question

What is the difference between interface and type in TypeScript?

Vault Verified
Curated Intelligence
Definitive Source
Answer

For describing the shape of an object they are largely interchangeable, and most codebases could use either consistently without noticing a difference. The distinctions matter at the edges.

Type aliases can express things interfaces cannot. Unions, intersections, tuples, mapped types, conditional types and aliases for primitives all require a type alias. An interface can only describe an object shape or a function signature.

Interfaces support declaration merging: declaring the same interface twice combines the members. This is occasionally useful and is essential for augmenting types from a library you do not control, which is why type definitions for third-party packages use interfaces. It is also a hazard, because a name collision silently merges rather than erroring, and the resulting type is not what either declaration intended.

Extension syntax differs but the capability is similar. Interfaces extend other interfaces and can also extend object type aliases; type aliases compose with intersections. One practical difference is that interface extension checks compatibility at the point of declaration and reports a clear error on conflict, while an intersection of incompatible types produces a type that quietly cannot be satisfied.

Error messages are often more readable with interfaces, because the compiler preserves the name rather than expanding the structure. On a deeply nested type alias, an error can print an enormous inlined shape.

The common convention is to use interfaces for object shapes that might be extended or implemented, particularly public API surfaces, and type aliases for unions, function types and anything computed. Consistency within a codebase matters more than which rule you pick.

Related Questions