Choosing between an interface and a type alias is usually less about capability than about intent. This guide compares their practical differences, shows TypeScript examples for common designs, and provides a reusable checklist for public APIs, application code, classes, unions, and evolving team conventions.
Overview
In TypeScript, both interfaces and type aliases can describe object shapes. For a simple object, these declarations are often interchangeable:
interface User {
id: string;
name: string;
}
type User = {
id: string;
name: string;
};The important differences appear when the type must evolve or express something beyond a straightforward object. Type aliases can name unions, intersections, primitive types, tuples, mapped types, and conditional types. Interfaces are designed primarily for extendable object contracts and can participate in declaration merging.
| Scenario | Usually a good fit | Reason |
|---|---|---|
| Object-shaped public contract | interface | Communicates an extendable shape and works naturally with extends. |
| Union of alternatives | type | Type aliases can directly name unions and support discriminated patterns. |
| Intersection of reusable pieces | type or interface extends | Choose based on whether the composition is an object contract or a type expression. |
| Library augmentation | interface | Interfaces can merge when declarations share the same name in the appropriate scope. |
| Tuple, primitive, mapped, or conditional type | type | These are type expressions rather than named object contracts. |
| Class contract | Often interface | It clearly communicates the members a class must provide, though a suitable object type alias can also be implemented. |
This is a design guideline, not a compiler requirement. TypeScript allows a class to implement an interface or a compatible object type alias, and both forms can be used for many ordinary object definitions. Consistency and readability matter more than treating one keyword as universally superior.
Checklist by scenario
When defining an object-shaped API
Start with an interface when you are naming a contract that consumers may extend:
interface RequestOptions {
timeoutMs?: number;
signal?: AbortSignal;
}
interface AuthenticatedRequestOptions extends RequestOptions {
token: string;
}This style makes the relationship between the base and extended contracts explicit. It is useful for SDK options, component props, service boundaries, and domain models that are expected to gain related variants.
When modeling alternatives
Use a type alias for a union. A discriminated union gives control-flow narrowing a reliable field to inspect:
type Result<T> =
| { status: 'success'; value: T }
| { status: 'error'; message: string };
function readResult(result: Result<number>) {
if (result.status === 'success') {
return result.value.toFixed(2);
}
return result.message;
}The same approach works for UI state, command objects, event payloads, and API outcomes. A union is often clearer than one interface containing many optional properties, because each valid state is represented separately.
When combining types
Use an intersection when you are composing type expressions:
type Timestamped = {
createdAt: Date;
};
type AuditRecord = User & Timestamped;For object inheritance, an interface can be more communicative:
interface AuditRecord extends User {
createdAt: Date;
}Prefer extends when the relationship is a clear object hierarchy. Prefer an intersection when the composition is assembled from type-level building blocks, especially when those blocks may include unions or utility types.
When defining classes
An interface is a readable way to describe a capability a class must provide:
interface Cache {
get(key: string): string | undefined;
set(key: string, value: string): void;
}
class MemoryCache implements Cache {
private values = new Map<string, string>();
get(key: string) {
return this.values.get(key);
}
set(key: string, value: string) {
this.values.set(key, value);
}
}Use an interface when the name represents a role or contract. A type alias remains reasonable if the contract is already a composed object type.
When working with framework code
Framework conventions should be part of the decision. For React props, either form can work, but use a union for mutually exclusive prop variants and an interface for a stable, extendable props object. For Node.js services, interfaces can describe injected dependencies while type aliases model request outcomes or configuration transformations. In all cases, let the behavior you need determine the declaration rather than applying a blanket rule.
What to double-check
- Object shape or type expression? If the name describes a normal object contract, an interface is a natural starting point. If it describes a union, tuple, mapped type, or conditional result, use a type alias.
- Will consumers augment it? Interfaces support declaration merging, which can be useful for intentionally extensible library contracts. It can also create surprising changes if duplicate names appear accidentally, so use it deliberately.
- Is the composition clear? Prefer interface
extendsfor a visible object relationship. Use intersections for composition, but remember that conflicting properties can produce an unusable type. - Are optional properties hiding invalid states? A single interface with several optional fields may allow combinations your program cannot handle. Consider a discriminated union instead.
- Does the type cross a package boundary? Public declarations should be easy to discover, extend, and explain. Document whether consumers should implement, extend, or merely read the type.
- Does the compiler configuration expose a problem? Strict settings can reveal incompatible overrides, missing properties, and unsafe assumptions. Check the declaration under the same
tsconfigused by the consuming package.
TypeScript's structural typing also matters: a value is generally compatible when it has the required shape, regardless of whether it came from an interface or a type alias. Neither keyword creates runtime validation. If data comes from an HTTP request, file, or other untrusted source, pair the static type with runtime validation rather than treating a type annotation as a check.
Common mistakes
- Assuming interfaces are always better for objects. For many object shapes, the two forms behave similarly. Choose based on extension, merging, composition, and team readability.
- Using an interface for every union. Interfaces cannot directly express a union of unrelated alternatives. A type alias is the direct and readable tool for that job.
- Using intersections to represent mutually exclusive states. An intersection requires all members at once. Use a union when a value can be one shape or another.
- Relying on declaration merging accidentally. Reusing a common interface name can merge declarations in ways that are difficult to trace. Keep names specific and use augmentation only as an intentional design feature.
- Confusing type design with runtime behavior. Renaming an interface to a type alias does not validate input, remove properties, or transform JavaScript objects.
- Mixing conventions without a reason. A codebase can use both forms successfully, but reviewers should be able to infer why a declaration uses one or the other. Record the convention in the project guide and make exceptions explicit.
During a JavaScript-to-TypeScript migration, do not spend effort converting every declaration to one preferred keyword. First model real boundaries, narrow unsafe values, and keep the build passing. You can refine naming and composition after the type relationships are understood.
When to revisit
Revisit an interface-versus-type decision when the underlying design changes, not simply when a new TypeScript version is released. Check it when an object gains multiple variants, when a package becomes a public API, when consumers need deliberate augmentation, or when repeated intersections become difficult to read.
Use this short review before merging a new type:
- Write down whether the declaration is an object contract, a union, or a more general type expression.
- Choose
interfacefor an intentionally extendable object contract andtypefor unions, tuples, mapped types, conditional types, and composition that is clearer as an expression. - Test representative valid and invalid values with the project's actual strict compiler settings.
- Check whether optional properties should become a discriminated union.
- Review package-boundary behavior, declaration output, and any intended augmentation.
- Record the choice if the repository has a team convention, then revisit the convention during a tooling or workflow change.
The practical answer to “interface or type in TypeScript?” is therefore conditional: use the form that makes the intended relationship easiest to understand and safest to evolve. Consistent reasoning is more valuable than a universal preference.