Lesson

TypeScript Aliases & Interfaces

10 min reading
Free Course

TypeScript Type Aliases vs. Interfaces: Choosing the Right Tool

Both type aliases and interface declarations let you name custom object contracts in TypeScript. While they overlap heavily for plain objects, each has unique strengths that determine which one fits best.

An interface specializes in object shapes and class contracts (implements), whereas a type alias can name anything—unions, primitives, tuples, and mapped types.

Key Differences at a Glance

flowchart TD
    A["Custom Type"] --> B["interface"]
    A --> C["type Alias"]
    B --> D["extends & implements"]
    B --> E["Declaration Merging"]
    C --> F["Unions, Tuples, Primitives"]
    C --> G["Mapped & Conditional Types"]

Practical Example of Both Working Together

Use interface (or type) for object models, and type whenever you combine shapes with | unions:

interface BaseEntity {
  id: number;
  createdAt: string;
}

interface Article extends BaseEntity {
  title: string;
  published: boolean;
}

type PublishState = "draft" | "review" | "live";
type ApiId = number | string;

const post: Article = { id: 1, createdAt: "2026-11-12", title: "TS Guide", published: true };
const state: PublishState = "live";
console.log(post.title, state);

Declaration Merging

Declaring the same interface Window twice merges their fields automatically—which is how libraries augment Express Request or global Window types. Declaring the same type twice raises a duplicate identifier error.

Common Mistakes to Avoid

  • Trying to extend a union with interface UserProfile extends MyUnion: Interfaces can only extend object-like types with statically known keys; use type UserProfile = MyUnion & { extra: string } instead.
  • Mixing type and interface inconsistently in one module: Pick one team convention for object shapes (for example, interface for public APIs/classes, type for unions and props) and stay consistent.
  • Accidental declaration merging: Reusing a generic interface Config name in the same scope silently merges both definitions.

Frequently Asked Questions

Is there any runtime performance difference between type and interface?

None at runtime—both disappear completely in compiled JavaScript. In very huge projects, interface extends can cache slightly faster in tsc than deep & intersections.

Can a class implement a type alias?

Yes, as long as that type describes an object shape rather than a union of multiple shapes.

When is type mandatory?

Whenever you define union types ("a" | "b"), tuple types ([number, string]), function signatures, or mapped/conditional types.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
TypeScript Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum