Difference between Type and Interface in TypeScript
Ever stared at a TypeScript file and thought: “Wait… why did I just use type
here instead of interface
?” Yeah. Me too. And honestly? It’s not always obvious. Feels like choosing between ketchup and mustard on a hot dog — both kinda work, but someone out there will judge you hard.
Let’s cut through the noise. No fluff. Just real talk, weird analogies, and a few hot takes. We’re diving into the Type vs Interface tango in TypeScript. Not the textbook way. The way — like explaining quantum physics using pizza toppings.
Imagine you’re building a Lego city.
interface
? That’s your modular Lego baseplate. You snap pieces together. Want to extend a house? Just click another block on top. Need a balcony? Attach it. Tomorrow? Add solar panels. It’s open-ended. Evolves. Grows. Like a Tamagotchi, but less tragic when you forget it.
Now type
? That’s your custom 3D-printed Lego piece. Precise. Sharp edges. Does exactly what you designed. But once it’s printed? No modifications. Want changes? Recreate the whole thing. Brutal. Efficient. Final.
That’s the vibe.
So What’s the Real Difference?
Let’s not sugarcoat it — in 90% of cases, they do almost the same thing. You can define object shapes, functions, even unions. But the devil’s in the details. And TypeScript’s devil wears Prada and judges your code style.
1. Extensibility: The Big One
interface
can be reopened. Like a restaurant that closes at 3 PM and magically reopens at 7 with a new menu.
interface Cat {
meow: () => string;
}
// Later, somewhere else in your code...
interface Cat {
purr: () => string;
}
// Boom. Cat now has both meow AND purr.
// TypeScript just… merged them. No drama.
Try that with type
? Nope. Compiler throws a fit. “Cannot redeclare ‘Cat’”. It’s a one-shot deal. Like a tattoo you regret at 2 AM.
type Dog = {
bark: () => string;
};
type Dog = {
wagTail: () => void;
}; // ❌ Error. TypeScript says: "Nah, bro. Pick one."
So if you’re building a library, or expect your types to evolve across files? interface
is your BFF.
2. Flexibility in Shape
type
doesn’t play by the same rules. It’s… wilder. Can represent unions, tuples, mapped types, conditional types — stuff interface
just can’t handle.