DNS Explained Simply (And Why It Can Break the Internet)

✍️ mohamed bundid 📅 May 14, 2025

If you’re using TypeScript, you’ve likely come across both type and interface. While they can often be used interchangeably to define the shape of data, there are subtle differences that can affect how and when you use them.

What They Have in Common

Both type and interface let you describe the structure of objects, functions, or other data shapes. In most day-to-day use cases, either one will get the job done.


Key Differences

Featuretypeinterface
ExtensionCan combine multiple types using union and intersection (&)Can combine multiple types using union and intersection (&)
MergingCannot be re-declared — it’s fixed after definitionInterfaces with the same name are automatically merged
Use CaseGreat for union types, primitives, tuples, etc.Ideal for defining object shapes and class contracts
FlexibilityMore versatile for complex typesBetter for structural and OO-style designs

Which Should You Use?

  • Use interface when working with objects or class structures.

  • Use type when you need unions, intersections, or more flexible combinations.

In practice, consistency is more important than perfection. Pick one that fits your style or team conventions — and stick with it.