Learn TypeScript Generics In 13 Minutes

Поделиться
HTML-код
  • Опубликовано: 24 ноя 2024

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

  • @Oliver-rh5bv
    @Oliver-rh5bv 6 месяцев назад +67

    Very often it feels like - yes its totally clear and so easy - when watching videos like this.
    Then we go back to work and in most cases our problems are more complex and they still need some time to get around that barrier in the head and apply what we just have learned.
    I tought myself the generic stuff by using it in my daily work and I still keep watching videos like this to learn about the very edgew cases - the smart little things I missed in the documentation documents in the web.

  • @afrotechtips
    @afrotechtips 10 месяцев назад +35

    Whenever I find it very hard to grasp a concept, I run to this channel. You are the GOAT

  • @gyros9162
    @gyros9162 11 месяцев назад +17

    This is the shortest and best explanation generic types and functions I've ever saw

  • @waseemtahir6740
    @waseemtahir6740 8 месяцев назад +10

    This is shortest and the best explanation of generics in TS. Thanks for this Kyle.

  • @Martin97perussini
    @Martin97perussini 11 месяцев назад +91

    Excellent, you honored the "simplified" to your name with this video, really easy to understand this way

  • @lauragreen3132
    @lauragreen3132 9 месяцев назад +3

    I was baffled by Generics in the docs & other tutorials. This is incredibly helpful and clear. Thank you.

  • @yuvrajsingh-gm6zk
    @yuvrajsingh-gm6zk 2 месяца назад +1

    I just had completed the rust book and searching for the term "generics" on youtube, came across this video( just for second perspective to make the thing really sink in) nailed it!

  • @ANANDYADAV-sc1se
    @ANANDYADAV-sc1se 12 дней назад

    He is really a Beast at explanations. Making complex things simple and crisp.
    You are really doing a great job bro. Keep doing it for us.

  • @crvlwanek
    @crvlwanek 11 месяцев назад +50

    The type system in TypeScript is so much more expressive than other languages. It has great inferencing, keyof for derived types, even ternaries for narrowing/filtering types

    • @arshiagholami7611
      @arshiagholami7611 11 месяцев назад +11

      You need an expressive type system to support types in a dynamic scripting language.

    • @oscarljimenez5717
      @oscarljimenez5717 11 месяцев назад +1

      @@arshiagholami7611actually not, for example python type system is very basic.

    • @arshiagholami7611
      @arshiagholami7611 11 месяцев назад

      @@oscarljimenez5717 python doesn't have a type system. it's a type hint for your IDE.

    • @ElektrykFlaaj
      @ElektrykFlaaj 11 месяцев назад +5

      @@arshiagholami7611 Rust has even more expressive type system than TS, and it's a static typed language

    • @arshiagholami7611
      @arshiagholami7611 11 месяцев назад

      @@ElektrykFlaaj no it doesn't, i've coded in both languages for years and I can tell you typescript's type system is way more complex for obvious reasons. I love rust tho 😇

  • @AtaurRahman-vm1uz
    @AtaurRahman-vm1uz 7 месяцев назад +3

    Probably the best video for generics in youtube. Hats of man.

    • @true227
      @true227 6 месяцев назад

      is it a joke?

    • @AtaurRahman-vm1uz
      @AtaurRahman-vm1uz 6 месяцев назад

      @@true227 Why do you think its a joke? Simple explanation.

  • @NLJ-r9y
    @NLJ-r9y 11 месяцев назад +5

    Really need your nextjs course, Kyle!!!

  • @WebSurfingIsMyPastime
    @WebSurfingIsMyPastime 10 месяцев назад +1

    I needed more info on generics and I had already signed up for the react course on webdev. I'm glad I purchased the course on typescript. The extra info in your course was exactly what I needed to guide me through a basic understanding of generics.

  • @kanfit
    @kanfit 5 месяцев назад

    brief and get to the point, really appreciated

  • @SirojiddinMirzayev-zy3pl
    @SirojiddinMirzayev-zy3pl 6 месяцев назад

    You are the one of the teacher who I know in RUclips , I did not understand until I watched this video why we needs typescript

  • @miladevs
    @miladevs 5 месяцев назад

    This video is a great introduction to generics! Generics can be a confusing topic, but this video breaks it down into clear and easy-to-understand concepts. I especially liked the way he showed how to use generics with API responses. This is a common use case for generics, and it was helpful to see how to create a generic API response type that can be reused for different API endpoints.

  • @therealj4282
    @therealj4282 8 месяцев назад

    Nice clear explanation - so many people get tied up in knots trying to explain generics.

  • @srleom
    @srleom 6 месяцев назад

    Simply the best explanation of TypeScript generics out there. Kyle, you're a legend. Thanks for making these videos 🙏🏻

  • @caioveb
    @caioveb 8 месяцев назад

    The best drops of knowledge in video I ever seen! Congratulations, man! And thank you very very much

  • @thedrew6905
    @thedrew6905 6 месяцев назад

    short and concise, i always come back to refresh my memory

  • @felistusobieze8951
    @felistusobieze8951 11 месяцев назад +1

    I enjoyed this. Thanks for clarifying. I actually use this but never knew I was implementing a generic type system.
    Learnt new stuff today.

  • @anotherhumanLingLing
    @anotherhumanLingLing 6 месяцев назад

    Wow, this is the first time I feel like I understand what Generics type is. BIG THANK YOU!

  • @adreto2978
    @adreto2978 5 месяцев назад

    Wow this actually exactly what I need to clean up some messy types in my current project.

  • @fabianpetersen2452
    @fabianpetersen2452 11 месяцев назад +2

    I'm currently learning Typescript and struggled a lot getting used to the syntax and trying to figure out what must be passed in to remove all these errors even though the code is correct with plain react/javascript. Thanks Kyle, this will assist me tremendously going forward.

  • @bencipherx
    @bencipherx 7 месяцев назад

    I have not started watching this but when I saw the video, I said if I don’t understand this concept after watching your videos then I can never understand it from anywhere else. Already seeing positive comments so 😅fingers crossed 🤞

  • @Belgabor
    @Belgabor 11 месяцев назад

    Very good introduction. One thing I would recommend for people just starting to learn this, do not even start naming generic parameters with single letters, be expressive. You may start out with a simple type where it's clear what 'T' is, but after a few weeks it has T, R, E, O and W. And a month later you have no idea any more what each of the letters are supposed to mean.

  • @fifty-plus
    @fifty-plus 11 месяцев назад +14

    Its a better practice to name your generic arguments prefixed with T, like TModel, TRequest, etc. like we do in C#. Yes it's Hungarian-like but it works well to distinguish generic arguments while keeping them explicit and descriptive.

    • @ivan.jeremic
      @ivan.jeremic 11 месяцев назад +2

      Hungarian-like. What does that even mean?

    • @fifty-plus
      @fifty-plus 11 месяцев назад +3

      @@ivan.jeremic Hungarian notation.

    • @IannoOfAlgodoo
      @IannoOfAlgodoo 11 месяцев назад +1

      Marking your type in TS with T, makes code messy IMO.

  • @khawajamohsin7194
    @khawajamohsin7194 11 месяцев назад

    I just realised how much i needed this video. Good work.

  • @Matiast9477
    @Matiast9477 11 месяцев назад

    This was great, now I need to understand when you get to that point where you see stuff like T extende keyof K or something like that

  • @ClaytonBoyle
    @ClaytonBoyle 8 месяцев назад

    Just an amazing 12 minutes of content. Thank you so much

  • @anruntxd8711
    @anruntxd8711 6 месяцев назад

    Thank you so much, your explanation was really easy and helpful!

  • @pro100tom
    @pro100tom 11 месяцев назад

    Man, after watching all kinds of your videos I am now convinced you are the one to explain the monads!

    • @fifty-plus
      @fifty-plus 11 месяцев назад

      Monads are easy but often over complicated. ruclips.net/user/shortsC2-ljnsckrs?si=cHTDnp5xmdRE_b9f

  • @leobertobittencourtfilho3036
    @leobertobittencourtfilho3036 6 месяцев назад

    Goodness me, and you're not even cutting the video every time! Cheers, mate!

  • @eduardherasym689
    @eduardherasym689 9 месяцев назад

    best webDev channel. Thanks)

  • @MagicPants647
    @MagicPants647 11 месяцев назад +2

    I like thinkin of generics as just a way to pass in types to a function or another type. kinda like how you’d pass in parameters to a function.

  • @mondirhallouli
    @mondirhallouli 11 месяцев назад

    great video! finally got a better idea on how generics work. I had the basic notion but never understood them like this. They are kinda placeholders for a type(s).

  • @maxidietz429
    @maxidietz429 2 месяца назад

    Short question about generics.
    When I have this type:
    export type TExtensionConfig = {
    oExtClass: TExt;
    oExtConfig?: ConstructorParameters[1];
    };
    How look's the array type for this?
    Background. I woul'd like to have a settings object who have a property "aExtensions".
    Each extension object should have a property called "oExtClass" for defining the extension class and an optional property called "oExtConfig".
    Each array item can have another extension / another generic class.
    The extension class is a abstract.
    Thanks.

  • @romaniaplus
    @romaniaplus 11 месяцев назад

    Love to see you simplifying the crazy webdev today everything build on top of everything. This mess starts to kill me.

  • @ahsanimam5243
    @ahsanimam5243 5 месяцев назад

    Hey @kyle,
    That is an awesome video.
    I wanted to point something in your last example regarding object. The value of new Date() would resolve to `object` so that might not work well. I think a more robust definition for an object would be Record or something along those lines. What are your thoughts?
    And thanks once again for another great video.

  • @v23452
    @v23452 Месяц назад

    Very good! Thanks! Could you cover how I can use types, interfaces, enums to replace the JavaScript constants during code migration

  • @theisoj
    @theisoj 11 месяцев назад +3

    Great video so far! Thanks Kyle as always! 👍

  • @jattoritittor8342
    @jattoritittor8342 9 месяцев назад

    Thank you very much for always simplifying very well this kind of typescript concepts :D

  • @Cognitoman
    @Cognitoman 8 месяцев назад +1

    Think of generics like functions for types, the generic takes a type as an argument. Once you think of it like that… it’s easy

  • @Amanrauniyar-dm7in
    @Amanrauniyar-dm7in 9 месяцев назад

    brother your next level thankyou for all these

  • @magorzatagajlusz9170
    @magorzatagajlusz9170 8 месяцев назад

    so amazing! it's really easy to understand 😄

  •  11 месяцев назад

    You really do the web dev simplified!!!😀

  • @abhidadhaniya5701
    @abhidadhaniya5701 10 месяцев назад

    Great video kyle, Please cover keywords like Infer, As and Satisfy in Typescript. Thank you.

  • @shreyas12321
    @shreyas12321 6 месяцев назад

    Cool thumbnail. That was the exact emotions I was going through before seeing this video :) Thank you for the video

  • @Vptechvelly
    @Vptechvelly 8 месяцев назад

    Easy explanation ,Simplified the explanation of generic type easy to understand.

  • @PrabhuKripaHai
    @PrabhuKripaHai 11 месяцев назад

    Nicely explained, it just fit into my mind. Thanks.😊

  • @pakistanigymers2k22
    @pakistanigymers2k22 11 месяцев назад

    Loved your explanation!!! 😁

  • @jasonlough6640
    @jasonlough6640 11 месяцев назад

    At 4:02, you pass to tell it what the generic value passed in should be. Makes sense.
    At 4:37, you seem to be passing in... the return type? querySelector, now input is of type HTMLInputElement.
    so which is it, the type passed in or a return type?

    • @kenichiwaaa
      @kenichiwaaa 11 месяцев назад +2

      If you pause at 4:42, you can see that the generic is placed after the semicolon, meaning the return type.
      At 4:02, Kyle specifically use the generic for the parameter passed in.
      So it can be both. It is just a matter of how and where you define it

    • @LittleLily_
      @LittleLily_ 10 месяцев назад +1

      The generic type can be used anywhere in the function, either in the input arguments, the return type, or even both. For example:
      function foo(a: T) { return "foo" }
      function bar(a: T): T { return a }
      function getFoo(obj: { foo: T }): T { return obj.foo }

  • @gageracer
    @gageracer 11 месяцев назад +2

    bro, you just explained it so well! Now I don't hate generics that much. My only issue was that for some reason you need to put generics between the name and the parenthesis. I was trying to use it for svelte 5 props and was doing: let {name} = $props() and had no idea why it wasn't working. fyi you need to do it $props()

    • @joe-skeen
      @joe-skeen 11 месяцев назад +5

      I think that choice came from other C-family languages that also use the same syntax for generics, like C# and Java to make it more approachable and intuitive for those developers. But for someone that hasn't worked with strongly typed languages in the past, they are understandably intimidating

  • @sergiom.954
    @sergiom.954 11 месяцев назад

    Great video! 👏I have been working with typescript for 3 years (angular) and I didn't even know this generic types possibilities.

  • @NazwaBricksZajeta
    @NazwaBricksZajeta 7 месяцев назад

    Thank you for clarifying this!

  • @rEmIxKoOL
    @rEmIxKoOL 10 месяцев назад

    Amazing! Clear and helpful

  • @tjohns92109
    @tjohns92109 8 месяцев назад +2

    Is Typescript really necessary? I have not wrapped my head around why there is a use to make code more complex just to make sure you are using the correct type of variables. I mean... I know what my variables are intended to be when I create them and when I use them later. So I'm not sure of the whole point of TS.

    • @lucasbezerra649
      @lucasbezerra649 6 месяцев назад

      JSDocs is a good alternative if you feel that way

  • @gunjangaba122
    @gunjangaba122 11 месяцев назад +3

    This is super useful for writing clean Typescript code. Thanks for sharing!

  • @aaadesh
    @aaadesh 5 месяцев назад

    Great content, well explained.

  • @secret786786
    @secret786786 9 месяцев назад

    Amazing video... Really helpful!!

  • @true_visual
    @true_visual 10 месяцев назад

    Thank you very very much for this tutorial! Can you please make a video about differences between Generics and Interfaces? I am pretty new and if someone would ask me to define a type of something, my mind thinks "Interface" at once!

  • @ozdenocak7937
    @ozdenocak7937 3 месяца назад

    great explanation!

  • @StephenRayner
    @StephenRayner 11 месяцев назад

    Already good with generics, this is a decent coverage of them.

  • @rajviahmed-r7c
    @rajviahmed-r7c 11 месяцев назад

    Great tutorial. Your explanation is awesome.

  •  11 месяцев назад

    thank you a much, I love your courses

  • @mukullataroy2195
    @mukullataroy2195 11 месяцев назад +117

    Ahh generics.... My worst enemy

  • @edisonj9664
    @edisonj9664 6 месяцев назад +2

    Typescript generics explained well

  • @jasonlough6640
    @jasonlough6640 11 месяцев назад

    Its weird, because one syntax
    function foo(n: string)
    says "this function will accept this kind of thing, which makes sure you only pass this kind of thing"
    while the other function
    foo(n:T)
    says "this function takes anything, but that anything is now consistent".
    The second one wont stop you from sending "apples" to function checkBankAccountBalance(n:T), so it seems counterproductive.

    • @stevezelaznik5872
      @stevezelaznik5872 11 месяцев назад +1

      The point of a generic is to define a relation between two or more things. For example a return type T of a function being the same as its argument type T. In your example the generic only applies to one thing, so it doesn’t define a relationship between anything.

    • @jasonlough6640
      @jasonlough6640 11 месяцев назад

      @@stevezelaznik5872 makes sense.

  • @alexanderkomanov4151
    @alexanderkomanov4151 11 месяцев назад

    Thanks a lot for this!

  • @ehsanset6709
    @ehsanset6709 8 месяцев назад

    Very helpful, Thanks

  • @Aditya-k4t
    @Aditya-k4t 4 месяца назад +3

    Informative but i got confused at the end

  • @ThangPhan-q3u
    @ThangPhan-q3u 6 месяцев назад

    Thank you so much, I really appreciate it :)

  • @iqbalibrahim4713
    @iqbalibrahim4713 11 месяцев назад

    You sir, are a hero

  • @valkopuhelin2581
    @valkopuhelin2581 5 месяцев назад

    Any video that shows all the keyboard typing shortcuts, many of which were used here and went over my head?

  • @fuadagayev-mg7fk
    @fuadagayev-mg7fk 8 месяцев назад

    Best Generics explain one of!

  • @norbusherpa3665
    @norbusherpa3665 7 месяцев назад

    it was so fun to watch this

  • @danilomourelle
    @danilomourelle 10 месяцев назад

    I don't know man. I would say that it gonna use extends a lot when using generics... Every time I neede an explicit generic, half of time is with extends... Great video by the way...

  • @YusufxonToshkandiy
    @YusufxonToshkandiy 8 месяцев назад +1

    perfect , and thanks bro

  • @angmathew4377
    @angmathew4377 5 месяцев назад

    Thanks for making it happen, do you do blazor, any content references?

  • @david.thomas.108
    @david.thomas.108 7 месяцев назад

    Super informative video thanks 👍

  • @superuser8636
    @superuser8636 11 месяцев назад

    Coming from C++, I love everything about TypeScript

  • @theidanking
    @theidanking 10 месяцев назад

    Thank you! You know how to explain

  • @mosescosme8629
    @mosescosme8629 10 месяцев назад

    My favorite part of this video was learning that I've already been using Generics everywhere and had no idea that's what they were called.

  • @dinguskhan8883
    @dinguskhan8883 11 месяцев назад

    Would love to see a video about what stuff makes typescript’s inference not work

  • @MrVipulLal
    @MrVipulLal 11 месяцев назад

    Brilliant video, as usual

  • @tubenzr
    @tubenzr 11 месяцев назад

    long time no see Kyle, as always great content. 👍👍👍

  • @hillelgarcia5140
    @hillelgarcia5140 5 месяцев назад

    very good stuff, thanks!

  • @thetruthofunknown
    @thetruthofunknown Месяц назад

    Thank you, brother :)

  • @LeVanHienFEFPLHN
    @LeVanHienFEFPLHN 7 месяцев назад

    Great video, thanks for kyle

  • @Kat8dev
    @Kat8dev 10 месяцев назад

    really good explanation

  • @tomasburian6550
    @tomasburian6550 10 месяцев назад +2

    Top. I'm to this day shocked how little attention people give to TS given that we use it everywhere in the professional world. Learning as much of it as possible can make a developer go a long way. The same goes for writing tests.

  • @bingers_uk
    @bingers_uk 11 месяцев назад

    Great video!

  • @_neuromanser_
    @_neuromanser_ 11 месяцев назад

    Never used this, but it seems useful.

  • @radomir_web
    @radomir_web 2 месяца назад

    Thanks!

  • @boxboxerson991
    @boxboxerson991 11 месяцев назад +1

    see this is good because it's not some vague opinion piece on how types are better than interfaces or some nonsense. exclusively stuff like this pls.

  • @_WyreZ
    @_WyreZ 11 месяцев назад

    So good. Ty!

  • @RandikaTechWork
    @RandikaTechWork 8 месяцев назад

    Rally good one .. Keep it up..!!

  • @HungNguyen-vi4rr
    @HungNguyen-vi4rr 11 месяцев назад

    8:00 no no, it is smart enough to force you to put the Generic Type there.
    If it automatically generated / inferred types there, Generic Type would be useless there: no validation errors, it works as 'any' type all the way :)).
    They need Generic Type to acknowledge that what type you want to validate "data"

  • @d-princecoder4031
    @d-princecoder4031 8 месяцев назад

    great simplification

  • @dawid_dahl
    @dawid_dahl 11 месяцев назад

    With (string | number)[] you said, when the type returned from getFirstElement was “string | number”:
    “But TypeScript is not smart enough to know that (what we passed in was actually a string).”
    It’s not that TS is not smart enough. It was that the type was explicitly set as “string | number”, and since the function has not actually been run yet, there is no way TS could possibly know that, no matter how smart it was. It was simply respecting the programmer’s wishes, not being stupid. 😄

  • @SlickStatus
    @SlickStatus 11 месяцев назад

    Very helpful ❤