Wait... type and interface look almost the same, right?
Both can describe objects. Both can define properties. And honestly, when you're starting with TypeScript, it's hard to understand why we even have both. But there's a difference. Let's build a simple user system and see where each one shines. Check TypeScript Handbook.
Let's Start with Type
Imagine we're building an application where users have a name and an email. We need to tell TypeScript what a valid user should look like. Here's how we can do that with type:
type User = {
name: string;
email: string;
};Pretty simple!
typecreates a new type.Useris the name we're giving it.name: stringmeans the name must be text.email: stringmeans the email must also be text.
Now let's create a user:
const user: User = {
name: "Shayon",
email: "shayon@example.com",
};TypeScript checks our object against the User definition. If we forget the email or use a number instead of a string, TypeScript shows an error.
Why do we need this?
Imagine writing the same object structure in 20 different places. That's a lot of repeated code. With a type alias, we define it once and use it wherever we need it.
Read article on "10 Next.js Security Mistakes"
What If We Want to Add More Fields?
Now our application is growing. Every user needs a unique ID. We could write the whole user structure again. But why do that when we already have User? We can use something called an intersection type.
type UserWithId = User & {
id: number;
};See that & symbol? It combines two type definitions. So UserWithId now has:
namefromUseremailfromUseridfrom the new definition
Let's use it:
const user: UserWithId = {
id: 1,
name: "Shayon",
email: "shayon@example.com",
};Everything works! This is useful when we want to reuse existing types instead of writing the same properties again and again. But there's a small problem. What if we want to add more properties to the original User type later? We cannot simply declare type User again. TypeScript will throw a duplicate identifier error. And that's where interface comes in.
Read article on "Choose Between FastAPI and Express.js"
Here's Where Interface Shines
Let's create the same user structure using an interface.
interface Customer {
name: string;
email: string;
}Looks familiar, right? We can use it just like a type:
const customer: Customer = {
name: "Shayon",
email: "shayon@example.com",
};Now here's the interesting part. Imagine another part of our application needs to add an ID to Customer. With an interface, we can declare the same interface again!
interface Customer {
id: number;
}What happens now? TypeScript automatically combines both definitions. This feature is called declaration merging. So our customer now needs all three properties:
const customer: Customer = {
id: 1,
name: "Shayon",
email: "shayon@example.com",
};No errors! Pretty cool, right? Why does this matter? Imagine you're using a third-party library. It already has an interface, but you need to add something to it. Declaration merging can help you extend that interface without changing the original library code. One thing to remember: you can't add conflicting definitions for existing properties. And unlike interfaces, type aliases don't support declaration merging.
Read article on "Boost Developer Energy on Hard Days"
Want a String OR a Number? Use Type!
Now let's look at another situation. Imagine our application has different IDs. Some are strings, like "user-101". Others are numbers, like 101. How do we allow both? Easy!
type ID = string | number;
const userId: ID = "user-101";
const productId: ID = 101;Look at the | symbol. It means OR. So the ID can be a string OR a number. This is called a union type.
Why is this useful?
Because real applications don't always receive data in the same format. One API might return an ID as a string, while another returns it as a number. Union types let us handle both without creating separate types.
Can we do this directly with an interface?
No. An interface describes an object or its structure. It cannot directly represent a union of primitive types like this. And that's one big reason we need type aliases.
Read article on "Resume Not Getting Interviews? Here's Why"
Both Can Extend Existing Structures
Wait, there's one more thing.Both type and interface can help us build new object structures from existing ones. They just use different syntax. With interface, we use extends:
interface Admin extends Customer {
role: string;
}This means an Admin has everything from Customer, plus a role. With type, we use &:
type Moderator = Customer & {
role: string;
};Same idea! We're combining the existing customer structure with a new property. Just remember that extends and & aren't exactly the same in every situation. If two properties have conflicting types, they can behave differently. For normal object structures, both approaches work nicely.
Read article on "OpenCode vs Claude Code"
Here's Something Many Developers Miss
You don't have to choose only one. You can use type and interface together! Look at this:
type AdminID = string | number;
interface TeamMember {
id: AdminID;
name: string;
}Here, we're using a type alias to define an ID that can be a string or number. Then we're using that type inside an interface. Totally valid! They aren't enemies. They work together.
So, When Should You Use Each?
Here's a simple guide:
Situation | Use |
|---|---|
Describing an object | Both |
Adding properties through declaration merging | Interface |
Extending an object with | Interface |
Creating union types ( | Type |
Creating intersection types ( | Type |
Defining primitive aliases | Type |
Defining tuples | Type |
My personal rule is simple:
Use interface when you're defining object structures that may need to be extended or merged. Use type when you need unions, intersections, tuples, or other flexible type definitions. But don't follow this rule blindly. Both can do more than you might expect.
What's Next?
So, what's the real difference between TypeScript types and interfaces?
Both can describe objects, but they have different features. Interfaces support declaration merging, while type aliases give us more flexibility with things like unions and intersections.
And the best part? You can use both in the same project.




