Intern / FresherTypeScript

What is the difference between interface and type in TypeScript?

Quick answer

Both describe object shapes. interface can be merged and is preferred for public object contracts; type can express unions, intersections and primitives, and cannot be reopened later.

For a simple object, they look the same and teams pick one style. interface supports declaration merging: two interface User blocks become one, which is how many .d.ts files extend library types. type aliases are fixed once written.

Use type when you need a union (string | number), a mapped type, or a tuple. Use interface when you are describing an object that others might extend. You can implement either with a class. Do not waste interview time claiming one is “faster”; they compile to the same nothing.

interface User { id: string; name: string }
interface User { email?: string }      // merged

type Id = string | number;             // union: type only
type Admin = User & { role: "admin" }; // intersection

Key points

  • interface: extendable, mergeable, object-shaped
  • type: unions, intersections, primitives, tuples
  • Pick one style for objects and stay consistent