Interfaces vs Type Aliases: what's the difference?

  Рет қаралды 22,956

Andrew Burgess

Andrew Burgess

Күн бұрын

Пікірлер
@ДаниилСоболев-щ4щ
@ДаниилСоболев-щ4щ 2 жыл бұрын
Man. You have amazing teaching skills. Every difficult issue becomes absolutely clear after watching you video! I will recommend your channel everybody! Thank you so much
@ilonachan
@ilonachan Жыл бұрын
I think with the "amalgamation" property of interfaces at the end, we can sum up this video in a very poetic way: "use types for types, and interfaces for interfaces." if you're defining a shorthand for a commonly used type of thing, that may involve unioning and all kinds of stuff, then use a type alias for that (you might have to anyway). if you're instead defining the structure of an API or class interface, which is supposed to be rigid and have no surprises, then interfaces have the slight advantage. Does this make sense?
@vimux
@vimux Жыл бұрын
10 mins ago, I'm scratching my head because Idk what to use and I see a bunch of docs or codebase using type and interface but I don't really know the difference. I got a lot of "Aha" moments watching this. Thank you man! Subscribed!
@kbsanders
@kbsanders Жыл бұрын
Clear. Concise. Expertly explained. Well done!
@deltaboukensha
@deltaboukensha Жыл бұрын
Man I find it madness that interfaces and types are so interchangeable
@aram5642
@aram5642 2 жыл бұрын
As always, one darn useful video! And I had a happy moment seeing that you also use a type for things like UserId! For exact same reason! I'd be curious to see a video about abstract classes. I think I know when to use them (esp in Angular) but it would be good to hear your explanation anyway.
@andrew-burgess
@andrew-burgess 2 жыл бұрын
Great idea, thanks!
@aram5642
@aram5642 2 жыл бұрын
@@andrew-burgess It would be super useful to hear your lecture about the 'declare' keyword. It can be confusing. Especially with const or let. After all these are all declarations, so why declare declarations ;) And how is 'declare function' different from specifying a function signature type, as in type PredicateFn = (value: any) => boolean (for example).
@DavidAguileraMoncusi
@DavidAguileraMoncusi Жыл бұрын
I use them too. But it bug me that they're only aliases and TS doesn't complain when i mix them up. Or should I say it USED to bug me? I discovered Andrew's video on Branded Types and I'm now using those instead (via a package named ts-brand). Totally recommend it!
@kouroshg4621
@kouroshg4621 Жыл бұрын
I personally like to use interfaces for my react component props and type for all other objects used. I come from c# and can’t help but to see resemblance of classes in react components although vastly different after introduction of hooks. Thanks for the in-depth comparison!
@jcollins519
@jcollins519 Жыл бұрын
Great video! I'd love to see more on the last topic you mentioned about having a global API interface that each module is capable of extending and the related gotchas that come along with that
@biskitpagla
@biskitpagla Жыл бұрын
Really just boils down to this: Want union types? -> use type alises. Want extension methods? -> use interfaces.
@ajgubi19
@ajgubi19 Жыл бұрын
Many thanks. Compared to other of the "popular" channels, your videos are simpler to understand. Please keep making videos. Subscribed. 💯
@producdevity
@producdevity 2 жыл бұрын
Your video’s are great! I was wondering why they didn’t pop up in my feed earlier, then I saw that nowhere in the title or description you mention typescript. Might be helpful for youtube algorithm to add it
@andrew-burgess
@andrew-burgess 2 жыл бұрын
Good point! 🙈 thanks for watching!
@FirstLast-kv1iq
@FirstLast-kv1iq 2 жыл бұрын
This was super useful! Thank you so much
@saketc2010
@saketc2010 Жыл бұрын
Confused with type:'admin'. Can you pls elaborate
@pgtechmedia5624
@pgtechmedia5624 5 ай бұрын
Really helpful. Thanks
@avi3681
@avi3681 2 жыл бұрын
Very clear video.
@redcrafterlppa303
@redcrafterlppa303 Жыл бұрын
I don't know about typescript but what you showed really defeats the purpose of the idea of interfaces. Interfaces are in concept types that define the minimal api surface a certain functionality should have. For example: interface List { add(val: T) : boolean get(index: int) : T set(index: int, val: T) } class ArrayList implements List {...} class LinkedList implements List {...}
@kugi7786
@kugi7786 Жыл бұрын
That was really helpful, thank you
@matthewlefevre5667
@matthewlefevre5667 Жыл бұрын
Very helpful. Thank you!
@bubu88134
@bubu88134 Жыл бұрын
Amazing
@rahimco-su3sc
@rahimco-su3sc Жыл бұрын
thanks | defenetly helpfull
@aamirsuleman9815
@aamirsuleman9815 Жыл бұрын
Adding a key “type” to an extended interface threw me off at 5:00 😂
@windar2390
@windar2390 Жыл бұрын
9:00 - For me thats the only reason to use interfaces.
@adriatic123
@adriatic123 9 ай бұрын
Problems with once potent javascript ecosystem were started once OOP programmers started to move into js world without respecting its specific strengths. Now we are forced not only to use js in an OOP way which is totally wrong, but they dont stop there but want to mould js js into a total OOP language. This shows not only lack of js knowledge but also a disrespect of all js community. I long for times where there were two independedt words, functional programming js world and OOP world
@pmioduszewski
@pmioduszewski 2 жыл бұрын
sub
@alexnh502
@alexnh502 Жыл бұрын
Super helpful, thank you.
any vs unknown vs never: TypeScript demystified
8:01
Andrew Burgess
Рет қаралды 24 М.
Branded Types give you stronger input validation
9:22
Andrew Burgess
Рет қаралды 18 М.
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 6 МЛН
Long Nails 💅🏻 #shorts
00:50
Mr DegrEE
Рет қаралды 15 МЛН
Why use Type and not Interface in TypeScript
14:12
ByteGrad
Рет қаралды 215 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 835 М.
Building Fluent Interfaces in TypeScript
16:15
Andrew Burgess
Рет қаралды 16 М.
will i never understand this? unknown.
12:05
Andrew Burgess
Рет қаралды 3,9 М.
old TypeScript syntax I just discovered
8:54
Andrew Burgess
Рет қаралды 4,1 М.
how Google writes gorgeous C++
7:40
Low Level
Рет қаралды 952 М.
How to use TypeScript Enums and why not to, maybe
12:43
Andrew Burgess
Рет қаралды 19 М.
Are your TypeScript Unions broken? | Advanced TypeScript
7:36
Andrew Burgess
Рет қаралды 8 М.