TypeScript: Should you use Types or Interfaces?

preview_player
Показать описание
Become a TypeScript Wizard with Matt's upcoming TypeScript Course:

Follow Matt on Twitter

Рекомендации по теме
Комментарии
Автор

Finally someone actually highlighted that Interfaces have different features from types. Good bless this man.

hugodsa
Автор

This is my preferred approach. Use types by default, and interfaces only when necessary. I find type intersections and unions to be very useful

JonathanRose
Автор

When the video is the normal distribution meme with the newbie and the guru saying "use types by default"
btw great content as always, love that you took on this journalistic effort, it's perfect to keep the pulse on TS world. Thank you!

marcomow
Автор

Man, this video just put an end to all the madness I've been through. Thank you very very much.

amin
Автор

Amazing deep dive into something that one would never even thing of existing in the first place! Bravo, Matt 🍻

petarkolev
Автор

Loved hearing your journey with this decision! It was very relatable, because I feel like I flip flop like this with everything in my life, not just technology...😅

bispingbraden
Автор

This is 100% my philosophy for interacting with types and interfaces. Awesome Video!

Svengtz
Автор

I'm a noob so of course at first (last week), I was using interfaces for anything and everything more than a one line type definition. I've been coming around to your way of thinking more over the past few days and I feel better after hearing what you have to say about it. Thanks

ThaRealIansanity
Автор

I also went back and forth between both for a while, but ultimately settled for something like you did. Use types when I need their features, use interfaces when I need their features. And, if I absolutely don’t need any of their features, that actually raise the question why and we try to figure out if we truly need that new type/interface in the way we see it. Oftentimes we realise that processing an existing type trough a generic or a mapped type.

arakwar
Автор

this video is very instructive for someone that doesn't went deep into types but still appreciate how is the common sense related to this way of typing things

snk-js
Автор

Small note: `types` unwraps to the underlying structures, `interfaces` preserve the "box" name throughout

GiovanniRavalico
Автор

Love it. Been using exclusively types for awhile mostly because of the consistency. Had no idea that interfaces even had these issues.

devanfarrell
Автор

This is just what I was looking for! Thank you

bytblitz
Автор

first time viewer. good content and also pleasant to watch. Thank you

vinhtrinh
Автор

Great explanation. Thank you, Matt. I've always been on the side of "use types for everything except if you want to use "class implements interface" feature. My reasoning was simply I don't have enough reasons to use interfaces for anything else.

romfrolov
Автор

Thank you! Wanted to know more about this and you explained it well! 🎉

realitydesigners
Автор

I use interfaces only in a 'classic' OO sense: describe abstractions which multiple classes can inherit and provide the functionality described by the interface. These are usually 'classic' OO objects with private data, getters/setter and member functions ... no 'weird' JS stuff :).
For all other purposes I find types to be superior (mainly due to discriminating unions). I also find describing a function via interface weird personally so I would always do it via type alias.

Автор

Great video, thanks a lot for sharing, I really love the way you're explaining things :)

vinception
Автор

I always did this without even thinking about it, it's awesome to know the Typescript guru also do the same.

Hackkit
Автор

For me is weird using types for everything because I always though interfaces are the entrypoints for connecting things, the shape of the IO of a thing, and types were entities. But I always ended up using types to avoid the augmentation, because that is tricky to visualize and handle sometimes (at least for me).

shinodinhaa