15. What are the differences between interface and type in TypeScript?

In TypeScript, both interface and type can be used to define object types, but there are some differences. Here are the key distinctions:

  1. Extending types: interface allows extending other interfaces using the extends keyword. On the other hand, type allows extending using the & (intersection) operation.
interface Person { name: string; } interface Employee extends Person { salary: number; }
type Person = { name: string }; type Employee = Person & { salary: number };
  1. Multiple declarations: interface allows for declaring the same interface multiple times, merging definitions. type does not support this feature. Therefore, the interface definition can be extended across multiple declarations.

  2. Complexity: type is more flexible than interface, as it can represent not only objects but also other types such as unions, tuples, or aliases for primitive types.

  3. Compatibility: type can be more complex when combining different types, but interface offers better readability and structure.

In conclusion, both interface and type have their uses, and the choice between them depends on the context.

devFlipCards 2025

Do you accept cookies?

Cookies are small amounts of data saved locally on you device, which helps our website - it saves your settings like theme or language. It helps in adjusting ads and in traffic analysis. By using this site, you consent cookies usage.