DEV Community

buildlogmmd
buildlogmmd

Posted on

When to Use `type` vs `interface` in TypeScript

✅ Use interface when:

  • You’re defining data models (User, Product, Order)
  • You want to extend later (e.g. interface Admin extends User)
  • You’re working with classes
  • You need declaration merging (e.g. in libraries or configs)
interface Product {
  id: string;
  name: string;
}
Enter fullscreen mode Exit fullscreen mode

✅ Use type when:

  • You need a union or intersection
  • You’re working with primitives, tuples or functions
  • You want to compose types (e.g. type A = B & C)
  • You’re defining utility types
type ID = string | number;
type ProductWithStock = Product & { stock: number };
Enter fullscreen mode Exit fullscreen mode

🧭 Simple rule of thumb:

  • For data models → use interface
  • For type combinations → use type

✍️ Part of my personal cheatsheet at buildlogmmd – for fast recall in work situations.

Top comments (0)