What are TypeScript Generics?
HTML-код
- Опубликовано: 24 авг 2024
- Let's continue delving into TypeScript!
This video goes into Generics. What are they? What do they do? Why do you care?
Learn about type variables. Type variables - what are those?! They are what make Generics work!
SITE: hswolff.com
TWITTER: / hswolff
This is the best resource I found to understand generics, thank you so much Harry!
Harry, this is golden! The best explanation of generics! Thank you.
You are welcome!
Very clear and straightforward explanation. Thanks!
After watch 4 other videos and still confused, this one finally made sense. Thanks.
Woo! Always the best to hear that!
I was skeptical before playing it but so happy now! thank you!!!
The most clear and concise definition of generics on all of RUclips
I was feeling really insecure, but then you made me feel type-safe.
Very easy and plain daily English, way to go!!!
You are a great teacher, Harry.
Thank you! 😃
An incredibly clear and concise guide to generics. Thank you!
Quick, easy and crystal clear. Cheers 👍
Literally the best explanation of generics, i was struggling in this topic. Thanks a lot and keep up the good work.
Subscribers +=1;
after watching a few videos, this one is the one with the clearest explanation on generics !! thanks for making it !!
Thanks a lot Harry, Finally I understand generic
Thanks Harry!
This absolutely cleared up the confusion I was experiencing...thank you!
Very helpful. Thanks 👍
awesome explanations
Super simple and to the point. Thanks!
Simple and clear explanation. I finally understand Generics. Thank you for the fantastic video 👍
The thing that I think you all explain wrong is the type inferring at the beginning of the function.
function removeItem (array: Array, item: T): Array
The LAST thing the code actually does is storing the type T to the beginning of the code
function removeItem
When you pass in the data (in this case an array of something and something), then the code stores that something as a variable named T at the beginning. That was the part that was the most confusing, how does the code know what T is when I haven't even gotten to it yet. Well, now you might know.
You did it again Harry. Thanks for this explanation, clarity 100% :)
Woohoo! What’s my batting average at??
Thanks a lot.
finally someone explaining generics without " function identity( ) ".
Haha, yay!
You're the best, Harry!
Hey thanks! You're the best!
Great video! Keep up the great work!
Thanks for this, made it so clear!
One of my favorite things from Java that JS doesn't have by default is the Optional wrapper class. Of course, it's less useful in JS because of the lack of types, and you can still build such a class anyway, but it's so much nicer in TypeScript. And that wouldn't be possible without generics.
best explanation
Hey, thanks! Means a lot to hear that!
I think I'm in love!!!
subscribed
king
function test(a:T, b:T):T {
const c: T = a + b;
return c;
}
const b = test(10, 10);
console.log(typeof b)
I got error: Operator '+' cannot be applied to types 'T' and 'T'.(2365)
Interesting. I'm more familiar with generics in Swift, but this brought up a question in my mind: how would this be handled if you passed in a type that wasn't handled well by a function within the class that you'd created? Maybe the example is too esoteric to be useful, but what if you passed in a String and one of your functions did something like square root?
Thanks dude!
You are welcome!
By the way:
arr.filter(num => num !== item); --> short way to get back an array without a specific value
Awesome video! :)
Yeah I wanted to mutate the array, not return a new array. filter returns a new array.
Thanks!
@@hswolff uhh u could just do
arr = arr.filter(num => num !== item)
why not do arr = arr.filter(num => num !== item) ?
7:10 what sorcery is this (I mean selecting and replacing)
ctrl+D after highlighting something
@@poopking8077 thank you!
I liked your way of explaining this concept. Still not very clear on how you can use these in a more practical way, but I will watch the next video to find out.
Haha, sounds good! The classic example for why Generics are needed is with map.
Without generics you'd need to have a mapStrings, mapNumbers, etc function. There'd be no way to write a generic map function for every different type.
With Generics you can!
That's money!
Dude TypeScript 😍
Are generic types type erased at compile-time in TypeScript?
Aren't all types erased at compile-time, since the JS it compiles to doesn't have type checking?
@@IceMetalPunk Maybe? Maybe not?
OOOOOOOOOOOOOOOOOOOhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh! 🙏🤯
Nice Generic video #joke
Lol!