TypeScript Interfaces vs Types: Differences, Examples, and When to Use Each
typescriptinterfacestype-aliasesadvanced-type-safetytypescript-best-practices

TypeScript Interfaces vs Types: Differences, Examples, and When to Use Each

TTypeScript.page Editorial Team
2026-11-30
6 min read

Compare TypeScript interfaces and type aliases with examples, scenario-based guidance, and a checklist for safer type design.

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.

ScenarioUsually a good fitReason
Object-shaped public contractinterfaceCommunicates an extendable shape and works naturally with extends.
Union of alternativestypeType aliases can directly name unions and support discriminated patterns.
Intersection of reusable piecestype or interface extendsChoose based on whether the composition is an object contract or a type expression.
Library augmentationinterfaceInterfaces can merge when declarations share the same name in the appropriate scope.
Tuple, primitive, mapped, or conditional typetypeThese are type expressions rather than named object contracts.
Class contractOften interfaceIt 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 extends for 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 tsconfig used 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Confusing type design with runtime behavior. Renaming an interface to a type alias does not validate input, remove properties, or transform JavaScript objects.
  6. 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:

  1. Write down whether the declaration is an object contract, a union, or a more general type expression.
  2. Choose interface for an intentionally extendable object contract and type for unions, tuples, mapped types, conditional types, and composition that is clearer as an expression.
  3. Test representative valid and invalid values with the project's actual strict compiler settings.
  4. Check whether optional properties should become a discriminated union.
  5. Review package-boundary behavior, declaration output, and any intended augmentation.
  6. 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.

Related Topics

#typescript#interfaces#type-aliases#advanced-type-safety#typescript-best-practices
T

TypeScript.page Editorial Team

Technical Editor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.