Learn TypeScript Generics In 13 Minutes

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

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

  • @Oliver-rh5bv
    @Oliver-rh5bv 7 หลายเดือนก่อน +74

    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.

    • @hassansyed6087
      @hassansyed6087 9 วันที่ผ่านมา +1

      Hey Oliver, how much of Generics are you using on a daily basis or monthly basis when developing with TS?
      I just finished learning the basics of TS and I'm under the assumption that 80/20 principle applies here.
      80% of typescript development comes from 20% of the core fundamentals such as type inference, type annotation, unions, and function return types.
      Past that, are generics SUPER DUPER important to use or can we take them lightly and just not focus too much ?

    • @Oliver-rh5bv
      @Oliver-rh5bv 9 วันที่ผ่านมา

      ​@@hassansyed6087 Generics have become an important part in my daily work. But we use them with care. Once you are into them and you understand them things can get very fast very complex, if you over-use them.
      Most common part to use Generics is when you have a method with a switch case in it, just switching between types of the same kind (implementing some interface). In this case you might want to introduce a generic method where your generic type is something like function myFunction(T myTypeInstance) { /* ... */ }

  • @afrotechtips
    @afrotechtips 11 หลายเดือนก่อน +43

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

  • @waseemtahir6740
    @waseemtahir6740 9 หลายเดือนก่อน +12

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

  • @gyros9162
    @gyros9162 ปีที่แล้ว +19

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

  • @Martin97perussini
    @Martin97perussini ปีที่แล้ว +93

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

  • @lauragreen3132
    @lauragreen3132 10 หลายเดือนก่อน +4

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

  • @yuvrajsingh-gm6zk
    @yuvrajsingh-gm6zk 3 หลายเดือนก่อน +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!

  • @NLJ-r9y
    @NLJ-r9y ปีที่แล้ว +5

    Really need your nextjs course, Kyle!!!

  • @ANANDYADAV-sc1se
    @ANANDYADAV-sc1se หลายเดือนก่อน

    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 ปีที่แล้ว +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

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

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

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

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

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

    • @ElektrykFlaaj
      @ElektrykFlaaj ปีที่แล้ว +5

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

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

      @@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 😇

  • @caioveb
    @caioveb 8 หลายเดือนก่อน

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

  • @miladevs
    @miladevs 6 หลายเดือนก่อน

    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.

  • @sergiofernandeztesta6433
    @sergiofernandeztesta6433 7 วันที่ผ่านมา

    Dude, this is exactly what I needed, amazing video! 👏👏👏

  • @AtaurRahman-vm1uz
    @AtaurRahman-vm1uz 8 หลายเดือนก่อน +3

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

    • @true227
      @true227 7 หลายเดือนก่อน

      is it a joke?

    • @AtaurRahman-vm1uz
      @AtaurRahman-vm1uz 7 หลายเดือนก่อน

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

  • @srleom
    @srleom 7 หลายเดือนก่อน

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

  • @SirojiddinMirzayev-zy3pl
    @SirojiddinMirzayev-zy3pl 7 หลายเดือนก่อน

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

  • @WebSurfingIsMyPastime
    @WebSurfingIsMyPastime 11 หลายเดือนก่อน +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.

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

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

  • @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 7 หลายเดือนก่อน

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

  • @fabianpetersen2452
    @fabianpetersen2452 ปีที่แล้ว +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.

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

    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_ 11 หลายเดือนก่อน +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 }

  • @bencipherx
    @bencipherx 8 หลายเดือนก่อน

    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 🤞

  • @adreto2978
    @adreto2978 6 หลายเดือนก่อน

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

  • @thedrew6905
    @thedrew6905 7 หลายเดือนก่อน

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

  • @MagicPants647
    @MagicPants647 ปีที่แล้ว +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.

  • @ahsanimam5243
    @ahsanimam5243 6 หลายเดือนก่อน

    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.

  • @kanfit
    @kanfit 6 หลายเดือนก่อน

    brief and get to the point, really appreciated

  • @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.

  • @rynare426
    @rynare426 2 วันที่ผ่านมา

    Idk how, but I always understand what you are saying and what ur trying to teach. English is my 2nd language and when I watch other tutorials it feels like WTH it's not understandable. But when I watch your videos it feels like this is so ez

  • @leobertobittencourtfilho3036
    @leobertobittencourtfilho3036 7 หลายเดือนก่อน

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

  • @shreyas12321
    @shreyas12321 7 หลายเดือนก่อน

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

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

    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. th-cam.com/users/shortsC2-ljnsckrs?si=cHTDnp5xmdRE_b9f

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

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

  • @lizaskoroglyad
    @lizaskoroglyad 26 วันที่ผ่านมา

    Dude thank you very much. You are literally a God

  • @KamasahDickson
    @KamasahDickson 14 วันที่ผ่านมา

    I watched several videos on this and I get rusty with It sometimes. you perfectly explained it.

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

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

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

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

  • @fifty-plus
    @fifty-plus ปีที่แล้ว +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.

  • @anruntxd8711
    @anruntxd8711 7 หลายเดือนก่อน

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

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

    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

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

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

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

    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).

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

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

  • @gageracer
    @gageracer ปีที่แล้ว +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 ปีที่แล้ว +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

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

    best webDev channel. Thanks)

  • @NazwaBricksZajeta
    @NazwaBricksZajeta 8 หลายเดือนก่อน

    Thank you for clarifying this!

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

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

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

    so amazing! it's really easy to understand 😄

  • @maxidietz429
    @maxidietz429 3 หลายเดือนก่อน

    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.

  • @abhidadhaniya5701
    @abhidadhaniya5701 11 หลายเดือนก่อน

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

  • @PrabhuKripaHai
    @PrabhuKripaHai 11 หลายเดือนก่อน

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

  • @sergiom.954
    @sergiom.954 ปีที่แล้ว

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

  • @Amanrauniyar-dm7in
    @Amanrauniyar-dm7in 10 หลายเดือนก่อน

    brother your next level thankyou for all these

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

    Loved your explanation!!! 😁

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

    Great video so far! Thanks Kyle as always! 👍

  •  ปีที่แล้ว

    You really do the web dev simplified!!!😀

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

    Amazing video... Really helpful!!

  • @langgs
    @langgs 19 วันที่ผ่านมา

    as soon as i get a job and my first salary i am buying your course . no shitting . btw that's real nice of you that you make a discount for people in such countries as russia , etc

  • @angmathew4377
    @angmathew4377 5 หลายเดือนก่อน

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

  • @aaadesh
    @aaadesh 5 หลายเดือนก่อน

    Great content, well explained.

  • @rEmIxKoOL
    @rEmIxKoOL 11 หลายเดือนก่อน

    Amazing! Clear and helpful

  • @YusufxonToshkandiy
    @YusufxonToshkandiy 8 หลายเดือนก่อน +1

    perfect , and thanks bro

  • @ozdenocak7937
    @ozdenocak7937 4 หลายเดือนก่อน

    great explanation!

  • @ThangPhan-q3u
    @ThangPhan-q3u 7 หลายเดือนก่อน

    Thank you so much, I really appreciate it :)

  • @rajviahmed-r7c
    @rajviahmed-r7c ปีที่แล้ว

    Great tutorial. Your explanation is awesome.

  • @Cognitoman
    @Cognitoman 9 หลายเดือนก่อน +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

  • @david.thomas.108
    @david.thomas.108 8 หลายเดือนก่อน

    Super informative video thanks 👍

  • @norbusherpa3665
    @norbusherpa3665 8 หลายเดือนก่อน

    it was so fun to watch this

  •  ปีที่แล้ว

    thank you a much, I love your courses

  • @fuadagayev-mg7fk
    @fuadagayev-mg7fk 8 หลายเดือนก่อน

    Best Generics explain one of!

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

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

  • @iqbalibrahim4713
    @iqbalibrahim4713 11 หลายเดือนก่อน

    You sir, are a hero

  • @deogenesabejuelajr6701
    @deogenesabejuelajr6701 6 หลายเดือนก่อน

    AMAZING!!!!🙌🙌👋👋👋

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

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

  • @true_visual
    @true_visual 11 หลายเดือนก่อน

    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!

  • @tubenzr
    @tubenzr 11 หลายเดือนก่อน

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

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

    Very helpful, Thanks

  • @thetruthofunknown
    @thetruthofunknown 2 หลายเดือนก่อน

    Thank you, brother :)

  • @theidanking
    @theidanking 11 หลายเดือนก่อน

    Thank you! You know how to explain

  • @hillelgarcia5140
    @hillelgarcia5140 6 หลายเดือนก่อน

    very good stuff, thanks!

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

    Thanks a lot for this!

  • @LeVanHienFEFPLHN
    @LeVanHienFEFPLHN 8 หลายเดือนก่อน

    Great video, thanks for kyle

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

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

  • @valkopuhelin2581
    @valkopuhelin2581 6 หลายเดือนก่อน

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

  • @mosescosme8629
    @mosescosme8629 11 หลายเดือนก่อน

    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.

  • @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"

  • @radomir_web
    @radomir_web 3 หลายเดือนก่อน

    Thanks!

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

    Brilliant video, as usual

  • @renishcharaniya6532
    @renishcharaniya6532 11 หลายเดือนก่อน

    Which extension are you using? the one when you Hover shows the ts types passed.

  • @tomasburian6550
    @tomasburian6550 11 หลายเดือนก่อน +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.

  • @kylesandstrom853
    @kylesandstrom853 8 หลายเดือนก่อน

    Great video and explanation as always, I really like your video tutorials... but TS still feels like overkill in most use cases I've seen.

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

    Great video!

  • @Kat8dev
    @Kat8dev 11 หลายเดือนก่อน

    really good explanation

  • @MuhammadumarSotvoldiev
    @MuhammadumarSotvoldiev 3 หลายเดือนก่อน

    Thank you very much

  • @sagarmahor1526
    @sagarmahor1526 7 หลายเดือนก่อน

    Ok lets just say if my functions has to support both string and sting[ ]. so instead of doing Element : string| string[ ]
    how can I use generics here ?

  • @edisonj9664
    @edisonj9664 7 หลายเดือนก่อน +2

    Typescript generics explained well

  • @mukullataroy2195
    @mukullataroy2195 ปีที่แล้ว +120

    Ahh generics.... My worst enemy

    • @joe-skeen
      @joe-skeen ปีที่แล้ว +13

      Right next to regular expressions, no doubt 😉

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

      ​@@joe-skeenchatgpt used to do it's magic for me on regex

    • @elixirdeveloper6673
      @elixirdeveloper6673 11 หลายเดือนก่อน

      I feel u

    • @unleash-gamplay
      @unleash-gamplay 11 หลายเดือนก่อน

      Same to you

    • @elixirdeveloper6673
      @elixirdeveloper6673 11 หลายเดือนก่อน

      @@unleash-gamplay dw bro practice makes perfect

  • @d-princecoder4031
    @d-princecoder4031 9 หลายเดือนก่อน

    great simplification

  • @danilomourelle
    @danilomourelle 11 หลายเดือนก่อน

    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...