ummahusla / edvins-io

My digital garden
https://edvins.io
MIT License
5 stars 2 forks source link

types-vs-interfaces-in-typescript #28

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Types vs Interfaces in TypeScript | Edvins Antonovs

Learn key differences between types and interfaces in TypeScript

https://edvins.io/types-vs-interfaces-in-typescript

Cheuktingchan commented 1 year ago

Interesting! So can Interface can only be used for objects, but Type cannot be used for objects?

ummahusla commented 1 year ago

@Chektinchan I've spent some time learning more on a topic and I think the ts documentation nails my whole blog post in 2 senteces.

Type aliases and interfaces are very similar, and in many cases you can choose between them freely. Almost all features of an interface are available in type, the key distinction is that a type cannot be re-opened to add new properties vs an interface which is always extendable.

avg206 commented 1 year ago

@ummahusla And even though you can always use ‘&’ sign to extend a type with new properties :)