Skip to main content

Types Vs Interfaces

The core difference

Both name a shape you can reuse. The distinction:

  • type can name anything — objects, unions, primitives, tuples, function types.
  • interface can only describe an object (or a class/function shape). It cannot name a union or a lone primitive.
// type — works for any kind of type
type ID = string | number; // Valid: union
type Name = string; // Valid: primitive alias
type User = { name: string }; // Valid: object

// interface — objects only
interface UserI { name: string } // Valid: interface IDI = string | number; // Error: not possible

One capability interfaces have: declaration merging

Declare an interface twice and TypeScript merges them. type throws a duplicate-identifier error. This is why library authors use interfaces for public, extendable APIs.

interface Window { title: string }
interface Window { version: number }
// Window now has BOTH title and version

type Point = { x: number };
type Point = { y: number }; // Error: Duplicate identifier 'Point'

Which should you use?

A practical rule:

  • Reach for type by default — it's more flexible (unions, primitives, function types, tuples all need it).
  • Use interface when you specifically want an object contract that others may extend or merge (public library types, class implementations).

They overlap heavily for plain object shapes — pick one and stay consistent. The real decision points are: need a union/primitive? → type. Need merging/extension as a public API? → interface.