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

Комментарии • 61

  • @Lee-fn1fb
    @Lee-fn1fb 5 лет назад +18

    This is the best resource I found to understand generics, thank you so much Harry!

  • @justfly1984
    @justfly1984 5 лет назад +10

    Harry, this is golden! The best explanation of generics! Thank you.

    • @hswolff
      @hswolff  5 лет назад +1

      You are welcome!

  • @passby8070
    @passby8070 Год назад

    Very clear and straightforward explanation. Thanks!

  • @snoobydoo2671
    @snoobydoo2671 3 года назад

    After watch 4 other videos and still confused, this one finally made sense. Thanks.

    • @hswolff
      @hswolff  3 года назад +1

      Woo! Always the best to hear that!

  • @nikhilgoyal007
    @nikhilgoyal007 2 года назад

    I was skeptical before playing it but so happy now! thank you!!!

  • @renu3463
    @renu3463 3 года назад

    The most clear and concise definition of generics on all of RUclips

  • @rebornreaper194
    @rebornreaper194 2 года назад

    I was feeling really insecure, but then you made me feel type-safe.

  • @anngular2227
    @anngular2227 2 года назад

    Very easy and plain daily English, way to go!!!

  • @arungeorge4524
    @arungeorge4524 3 года назад

    You are a great teacher, Harry.

    • @hswolff
      @hswolff  3 года назад

      Thank you! 😃

  • @user-hx5cx9jo1z
    @user-hx5cx9jo1z Год назад

    An incredibly clear and concise guide to generics. Thank you!

  • @farhadinho9
    @farhadinho9 2 года назад

    Quick, easy and crystal clear. Cheers 👍

  • @alashish
    @alashish Год назад

    Literally the best explanation of generics, i was struggling in this topic. Thanks a lot and keep up the good work.
    Subscribers +=1;

  • @HarisKhan-bh6uj
    @HarisKhan-bh6uj 3 года назад

    after watching a few videos, this one is the one with the clearest explanation on generics !! thanks for making it !!

  • @nirmalb1504
    @nirmalb1504 2 года назад

    Thanks a lot Harry, Finally I understand generic

  • @JeanPierreJordan
    @JeanPierreJordan 3 года назад

    Thanks Harry!

  • @icemann155
    @icemann155 2 года назад

    This absolutely cleared up the confusion I was experiencing...thank you!

  • @srimalnishantha6700
    @srimalnishantha6700 2 года назад

    Very helpful. Thanks 👍

  • @josephwong2832
    @josephwong2832 3 года назад

    awesome explanations

  • @rohitkhanna8620
    @rohitkhanna8620 2 года назад

    Super simple and to the point. Thanks!

  • @Humanti4200
    @Humanti4200 3 года назад

    Simple and clear explanation. I finally understand Generics. Thank you for the fantastic video 👍

  • @kresimircosic3753
    @kresimircosic3753 3 года назад +1

    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.

  • @samtoya
    @samtoya 4 года назад

    You did it again Harry. Thanks for this explanation, clarity 100% :)

    • @hswolff
      @hswolff  4 года назад

      Woohoo! What’s my batting average at??

  • @daifuco
    @daifuco 2 года назад

    Thanks a lot.

  • @karan4345
    @karan4345 4 года назад +1

    finally someone explaining generics without " function identity( ) ".

  • @kevinnacario359
    @kevinnacario359 3 года назад

    You're the best, Harry!

    • @hswolff
      @hswolff  3 года назад

      Hey thanks! You're the best!

  • @creativedeveloper6921
    @creativedeveloper6921 4 года назад

    Great video! Keep up the great work!

  • @reqtified
    @reqtified 4 года назад

    Thanks for this, made it so clear!

  • @IceMetalPunk
    @IceMetalPunk 3 года назад

    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.

  • @yassine_klilich
    @yassine_klilich 5 лет назад +1

    best explanation

    • @hswolff
      @hswolff  5 лет назад

      Hey, thanks! Means a lot to hear that!

  • @siberiokhovonick
    @siberiokhovonick 4 года назад +1

    I think I'm in love!!!

  • @sampathkumarajjapaga9817
    @sampathkumarajjapaga9817 2 года назад

    subscribed

  • @cooldude3010
    @cooldude3010 4 года назад

    king

  • @mohanraj1368
    @mohanraj1368 2 года назад

    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)

  • @toastrecon
    @toastrecon 4 года назад

    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?

  • @thekeepersmusic
    @thekeepersmusic 5 лет назад

    Thanks dude!

    • @hswolff
      @hswolff  5 лет назад

      You are welcome!

  • @KozaKrisz
    @KozaKrisz 5 лет назад +2

    By the way:
    arr.filter(num => num !== item); --> short way to get back an array without a specific value
    Awesome video! :)

    • @hswolff
      @hswolff  5 лет назад +1

      Yeah I wanted to mutate the array, not return a new array. filter returns a new array.
      Thanks!

    • @thefreeze6023
      @thefreeze6023 5 лет назад +2

      @@hswolff uhh u could just do
      arr = arr.filter(num => num !== item)

    • @jermainebrayne437
      @jermainebrayne437 4 года назад

      why not do arr = arr.filter(num => num !== item) ?

  • @_dominikdominik_
    @_dominikdominik_ 3 года назад +1

    7:10 what sorcery is this (I mean selecting and replacing)

  • @danielstoicamusic
    @danielstoicamusic 4 года назад

    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.

    • @hswolff
      @hswolff  4 года назад +1

      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!

  • @ivan89pln
    @ivan89pln 2 года назад

    That's money!

  • @mouradaouinat8721
    @mouradaouinat8721 4 года назад

    Dude TypeScript 😍

  • @thatoneuser8600
    @thatoneuser8600 3 года назад

    Are generic types type erased at compile-time in TypeScript?

    • @IceMetalPunk
      @IceMetalPunk 3 года назад

      Aren't all types erased at compile-time, since the JS it compiles to doesn't have type checking?

    • @thatoneuser8600
      @thatoneuser8600 3 года назад

      @@IceMetalPunk Maybe? Maybe not?

  • @AnthonySherritt
    @AnthonySherritt 3 года назад

    OOOOOOOOOOOOOOOOOOOhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh! 🙏🤯

  • @ronaldurbina8233
    @ronaldurbina8233 3 года назад

    Nice Generic video #joke