Typescript Generics | Beginners Tutorial with Examples

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 พ.ย. 2024

ความคิดเห็น • 83

  • @DaveGrayTeachesCode
    @DaveGrayTeachesCode  2 ปีที่แล้ว +2

    In this tutorial, we'll learn about Typescript Generics and look at several examples of how to use them. If you have questions, please join my Discord server where I answer questions and you can chat with other web dev students: discord.gg/neKghyefqh

  • @caffeinated-pixels
    @caffeinated-pixels 2 ปีที่แล้ว +5

    I've been using typescript on an almost daily basis for the past five months now and I still find these videos useful. I also like that you explain everything in each video - how to set up the project, how to use VS Code, keyboard shortcuts, etc. A lot of TH-camrs advertise their tutorials as being for beginners but then completely fail to explain fundamental steps and concepts. Great stuff!

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +2

      Glad it was helpful! I really appreciate the feedback! 💯

  • @studyingasyouwere
    @studyingasyouwere 2 ปีที่แล้ว +6

    Thanks Dave. I learnt HTML and CSS from your videos from scratch and now I post my own web dev content! Thank you for inspiring me!

  • @madhavjha844
    @madhavjha844 ปีที่แล้ว +3

    It was tough for me, maybe I'll have to watch it again. Content was great as always.

  • @ScriptRaccoon
    @ScriptRaccoon 2 ปีที่แล้ว +1

    That example where the keys are inferred and you get that drop-down is just awesome. I think this showcases very well why TypeScript is not (what I still thought months ago) a burden, but rather a huge help. The compiler (or is it the editor?) tells me right away which values can be passed in. It guides me in the right direction all the time. Someone recently put out a tweet saying something like "Coding in JavaScript after coding with TypeScript for so long feels like driving without a steering wheel".

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +3

      Agreed and thanks! Yes, with Microsoft behind both TS and VS Code, the integration and dev experience is excellent. 💯

  • @aarondiaz2506
    @aarondiaz2506 ปีที่แล้ว +1

    Dave you the man! Best TS tutorial series i have seen on TH-cam, from beginner to "advance". It's long but pays off to see it (no more headaches from TS erros 🤣)

  • @oussemabouyahia474
    @oussemabouyahia474 10 หลายเดือนก่อน

    I have been a while using react with typescript and I thought that i know everything till I see this video, great content Dave , you are the best developer I ve never seen

  • @hosamgnaba3205
    @hosamgnaba3205 2 ปีที่แล้ว +2

    remember to keep striving for progress over perfection, and little progress everyday will go a very long way ... let saying : String[] = ['very','inspiring','saying',':)']... thank you man

  • @VanPetersonKpoti
    @VanPetersonKpoti 9 หลายเดือนก่อน

    I like all your content.
    They are always top notch and well done.
    Typescript Generics are not as complicated as we think.
    Thanks Dave.

  • @sinxenon3181
    @sinxenon3181 ปีที่แล้ว

    Amazing explanation! I'm shocked about how great teacher you are! Thanks a lot!!!

  • @regilearn2138
    @regilearn2138 2 ปีที่แล้ว +1

    Awesome, Eagerly wafting for your REACT with all the hooks/MERN/Redux + TYPESCRIPT ADVANCE real world project. ❤❤LOVE YOU DAVE❤❤

  • @me.0.0.0.0
    @me.0.0.0.0 2 ปีที่แล้ว

    Can you please also make video on either type for response handling
    type Left
    type Right
    Please make video on this

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว

      When you say response handling, I think of promises and fetch requests. Is there a link where you specifically saw these names for types? I can name a type anything and generics can also be anything.

  • @gmjitendra
    @gmjitendra ปีที่แล้ว

    Detailed explanation found here over TS Generics. Thanks Dave for this lovely video. :)

  • @loaiamer7097
    @loaiamer7097 2 ปีที่แล้ว +3

    Played 20 sec after video posted :D

  • @安全保密
    @安全保密 ปีที่แล้ว

    Dave is always there when you need help in the developer journey

  • @riyadhossain1706
    @riyadhossain1706 ปีที่แล้ว +1

    Thanks a lot for such an awesome Typescript playlist

  • @doongie07
    @doongie07 2 ปีที่แล้ว +3

    Hey Dave, have you thought about making a cloud computing course?

  • @shahramkhaleh3078
    @shahramkhaleh3078 2 ปีที่แล้ว +1

    Thanks. for Best typescript tutorial 🌹

  • @1conscience0dimension
    @1conscience0dimension ปีที่แล้ว

    Super clear and perfect examples

  • @roman_k89
    @roman_k89 2 ปีที่แล้ว +1

    thanks, Dave! Brilliant as always💙💛

  • @adelprog
    @adelprog ปีที่แล้ว

    null is an object, thanks for this information

  • @k303k
    @k303k ปีที่แล้ว

    Thanks a million Dave!

  • @NOTHING-en2ue
    @NOTHING-en2ue ปีที่แล้ว

    very nice tutorial, thanks a lot 💗

  • @user-wh6ki2oj3l
    @user-wh6ki2oj3l 2 ปีที่แล้ว

    Hi Dave, I hope next you make full tutorial about NextJS with real world project because I like your teaching style

  • @sparshverma1369
    @sparshverma1369 ปีที่แล้ว

    The first example reminds of templates in C++ in STL

  • @sonamohialdin3376
    @sonamohialdin3376 2 ปีที่แล้ว +1

    Amazing tutorial thank you

  • @harmez7
    @harmez7 2 ปีที่แล้ว

    thank you Mr. Gray

  • @harmez7
    @harmez7 2 ปีที่แล้ว

    that's some weird ass syntax right there
    but thanks to you Dave i had much easier time wrapping my head around it .
    Bring it on you flipping TS sonofa JS !
    aint gonna beat me !

  • @mohamadlakees8318
    @mohamadlakees8318 ปีที่แล้ว

    Hay Dave ,i have a question ,in user Array example i understand everything in example except the T[k][ ] ,why you wrote it like this ?

  • @denmccormik7654
    @denmccormik7654 2 ปีที่แล้ว +3

    Hello, Dave
    I've already asked this question on your discord channel, but maybe it will be useful for other people here:
    Can you explain why we use
    `as keyof T` on 11:05??
    Because for me `arg` is typeof T, not typeof `keys of T`
    So this is confusing
    `keyof T` returns union Type, not type describing object, but method `keys` expects object
    So to simplify it
    When we pass obj in our function
    { id:1, name: 2}
    It should look like
    Object.keys(arg as ("id" | "name"))
    But for me it doesn't make sense because arg should be object

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +2

      Object.keys() just returns the keys of the object as an array. We are checking to see if the generic data we passed to the function as arg is an object. If it is an object, we pass it to Object.keys() to iterate through the array. However, TS doesn't like that until we tell it arg is viewed as keys here.

    • @denmccormik7654
      @denmccormik7654 2 ปีที่แล้ว

      @@DaveGrayTeachesCode but how object can be viewed as union type of values?
      I understand if we use ` arg as {[key:string] : any} `
      But why TS accept `arg as `string | string | string``
      Keyof T returns string | string | string
      Arg is object
      So we tell TS that we pass string in method which expects only object
      And it works

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +1

      @@denmccormik7654 Object.keys() only returns the keys in an array. I cannot answer _why_ TS does things in a certain way, but this is what TS accepts here.

    • @denmccormik7654
      @denmccormik7654 2 ปีที่แล้ว

      @@DaveGrayTeachesCode Thank you, Dave. Maybe my question is extra stupid. I need some practice to discover it.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +2

      @@denmccormik7654 no question is stupid. That's how we learn. 💯

  • @ВладиславТравинский-к5ы
    @ВладиславТравинский-к5ы 2 ปีที่แล้ว

    Thank you, Dave

  • @skillkrio
    @skillkrio 2 ปีที่แล้ว +1

    Dave can you help me to setup my github. I always keep my notes in github but sometimes that needs to be updated too. I was thinking a clear way to do that. I saw you html repo where you had 10 seperate folder and one readme file inside one single repo. How you did that ? I tried doing that but commit history tracks the entire project but i wanted to have each separate folder to have its own commit history. Can you explain me how can i do that just like yours. seems like repo nesting.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +1

      What I do still has a commit history. I'm not creating branches but instead, just adding new folders to the same "main" branch. You may actually be interested in creating separate branches where each has its own history.

  • @fizzdevdesigns5699
    @fizzdevdesigns5699 ปีที่แล้ว

    Great series!!! Thank you so much! In the isTrue function, I kind of prefer an 'object' assertion in the object case because it feels more self-explanatory: if (isObj(arg) && !Object.keys(arg as object).length) return {arg, is: false}
    ... Does it make sense?

  • @shubhampatankar1468
    @shubhampatankar1468 2 ปีที่แล้ว

    Pls post video on angular

  • @7doors847
    @7doors847 2 ปีที่แล้ว +2

    Yeah! TS Tuesday 🤘! ( and maybe some tacos too 😂 )

  • @aleksandrpetrov3938
    @aleksandrpetrov3938 ปีที่แล้ว

    for some reason I don't have any type Error in the example with Object.keys(arg). But if I put as keyof T, I will get this error:
    "Conversion of type 'T' to type 'keyof T' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first."
    Why is that? ))

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  ปีที่แล้ว

      Sounds like you have something different from the example code - see the link to the course resources. However, the suggestion you received is talking about a double assertion where you say "as unknown" followed by "as keyof T". It can work in a pinch but no example here should need that.

  • @abubakarsadiqbilyamin7173
    @abubakarsadiqbilyamin7173 2 ปีที่แล้ว

    Great course. Really informative. I'd like to join the discord server but the link is expired. Could I have a more recent one?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว

      Strange because the link does not expire. I just checked. Here it is: discord.gg/neKghyefqh

  • @MuhammadSalmanAshraf-hy8gc
    @MuhammadSalmanAshraf-hy8gc ปีที่แล้ว

    please write problem statment before any example so that we try by ourself nd then match solution with yours

  • @kennedydre8074
    @kennedydre8074 ปีที่แล้ว

    can't we just use the any type?

  • @ahmedhassan_saver
    @ahmedhassan_saver 2 ปีที่แล้ว +1

    Can you please respond to my Twitter message asking you about coming videos titles in this playlist

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 ปีที่แล้ว +1

      Hello Ahmed, I do not check Twitter messages often. Please join my Discord that I check nearly every day: discord.gg/neKghyefqh

  • @robertkennedy7772
    @robertkennedy7772 ปีที่แล้ว

    promosm

  • @hamzabonga7884
    @hamzabonga7884 ปีที่แล้ว +1

    This is not a beginner friendly I have not understand a single example

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  ปีที่แล้ว

      Generics can be difficult to understand. Did you complete the previous 7 chapters before attempting this video? That will help.

    • @hamzabonga7884
      @hamzabonga7884 ปีที่แล้ว

      @@DaveGrayTeachesCode yes I did complete previous 7 chapters they are completely understandable

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  ปีที่แล้ว +1

      @@hamzabonga7884 Glad to hear I helped with those chapters. Maybe seek some other sources to understand generics if this video didn't help you.

  • @josippardon8933
    @josippardon8933 ปีที่แล้ว

    Despite video saying it is for beginners, it is not. Especially example with usersArray.

    • @siddiqahmed3274
      @siddiqahmed3274 ปีที่แล้ว

      You should follow the complete series. As this is almost the end of the series you cannot expect to grab all without practicing

    • @josippardon8933
      @josippardon8933 ปีที่แล้ว

      @@siddiqahmed3274 I have gone through every video in series till this one

    • @siddiqahmed3274
      @siddiqahmed3274 ปีที่แล้ว

      @@josippardon8933 okay that's good. I hope you have practiced that as well. This is is a advance concept so if you don't grasp it, leave it for now and when you need it you can come back. On the second note if you try the examples yourself, breaking it, you will get it.

  • @dzhaniivanov5837
    @dzhaniivanov5837 ปีที่แล้ว

    100k

  • @nikeshinoda-c3w
    @nikeshinoda-c3w ปีที่แล้ว +1

    Example is too long and complex for beginners. Should show how the 'T' works first.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  ปีที่แล้ว +1

      I cannot please everyone. Please feel free to make your own tutorial the way you would like it.

    • @Imam.Mehdi_
      @Imam.Mehdi_ 11 หลายเดือนก่อน

      ​​@@DaveGrayTeachesCode
      Yes ,,, instead of making generics easier you made it very difficult....
      You teaching style is good ...in this vide you just messed the generics in loops and isArray and null is object etc...which are difficult for beginners...
      I am not complaining...I am just a student watching your video,,, it was hard for as I came here to learn generics and got stuck in loops and null is Array etc