DEV Community

Discussion on: type vs interface in TypeScript

Collapse
janpauldahlke profile image
jan paul • Edited

could you give an example in which cases i would want the last thing with the merge? i dont quite get? lil slow sometimes. i mean i could jsut write it in one interface. you mean smthng like {...spreadRest} as so to see advantage?

Collapse
saadsharfuddin profile image
saad ahmad Author

Hey there! You are absolutely right, you can just write everything in one interface and personally that is what I usually do. I just wanted to point out that while declaration merging is not something you may use often, it is something that is possible.

Collapse
omprakashsridharan profile image
omprakashsridharan

A use case for this that I recently encountered is that, there is the Theme interface in material UI library for react and you can import it. After that you can create the same interface with extra custom properties like company specific color palette and standard size configs and declaration merging automatically adds these extended properties to that and your app can consume both the standard stuff in the theme interface and you get intellisense for your custom extensions as well. That's pretty cool in my opinion !

Collapse
saadsharfuddin profile image
saad ahmad Author

Oh this is a perfect example! Thanks for sharing!