Type vs Interface in TypeScript: What's the Difference & When to Use Each?
NJOKU SAMSON EBERE

NJOKU SAMSON EBERE @ebereplenty

About: A Software Engineer and Developer Advocate who loves sharing knowledge via writing, videos, mentorship, and working out. Please Subscribe: https://www.youtube.com/channel/UCcz5Bvr4kGHPFAjvnRhIQ4g

Location:
Abuja, FCT, Nigeria.
Joined:
Jan 10, 2020

Type vs Interface in TypeScript: What's the Difference & When to Use Each?

Publish Date: May 8
13 6

TypeScript offers two powerful tools for defining the shape of data: type and interface. But what’s the difference between them, and when should you use one over the other?

In this post, we'll cover everything you need to know about type vs interface, with examples, comparisons, and best practices.


🔹 What is a type in TypeScript?

A type is a TypeScript feature used to define aliases for primitive types, unions, intersections, tuples, and object shapes.

✅ Example:

type UserID = string | number;

type Point = {
  x: number;
  y: number;
};
Enter fullscreen mode Exit fullscreen mode

Types are flexible and work well for complex structures like mapped types, unions, and intersections.


🔸 What is an interface?

An interface is typically used to define the structure of an object. It supports declaration merging and is preferred for defining public APIs or class contracts.

✅ Example:

interface Person {
  name: string;
  age: number;
}
Enter fullscreen mode Exit fullscreen mode

You can extend interfaces to create complex structures.

interface Employee extends Person {
  role: string;
}
Enter fullscreen mode Exit fullscreen mode

🆚 Key Differences: type vs interface

Feature type interface
Object Shape Definition
Union/Intersection Types
Declaration Merging
Extending Types ✅ (via &) ✅ (via extends)
Use with Classes
React Props ✅ (often preferred)

🧠 When to Use type vs interface

Here are some common guidelines:

  • Use interface when:

    • You’re defining the shape of an object or class
    • You want to benefit from declaration merging
    • You're working with public APIs or React props
  • Use type when:

    • You need unions or intersections
    • You're defining primitive aliases or tuples
    • You're working with more complex type logic

💻 Real-World Example

// Using type
type User = {
  id: number;
  name: string;
};

type Admin = User & {
  role: 'admin';
};

// Using interface
interface IUser {
  id: number;
  name: string;
}

interface IAdmin extends IUser {
  role: 'admin';
}
Enter fullscreen mode Exit fullscreen mode

Both achieve similar results but may differ in behavior when extending or merging.


📽️ Watch the Full Video

Learn with visuals and live coding examples in this video:

👉 Watch now


🗨️ What Do You Prefer?

Do you use type, interface, or a mix of both in your projects? Let me know in the comments below or drop your questions!


🔖 Tags

TypeScript #WebDevelopment #Frontend #TypeVsInterface #JavaScriptToTypeScript #CodingTips #LearnToCode

Comments 6 total

  • Nevo David
    Nevo DavidMay 9, 2025

    Perfect timing for this cuz I always end up googling it again and again lol

  • Javier Escartin
    Javier EscartinMay 12, 2025

    Great examples to understand

  • Nathan Tarbert
    Nathan TarbertMay 13, 2025

    Been switching back and forth on this forever, honestly - you think it actually matters much once your codebase gets big?

    • NJOKU SAMSON EBERE
      NJOKU SAMSON EBEREMay 15, 2025

      Yes... I think so.

      I usually use TYPE for simple declarations, but INTERFACE for more complex declarations

      This may not have much impact but it keeps the codebase organised for me

Add comment