TypeScript's Utility Types... Blazing fast

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

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

  • @JulianColeman03
    @JulianColeman03 Год назад +148

    Maybe the most insightful 3 minutes of TypeScript in my life

    • @Archcorsair
      @Archcorsair Год назад +1

      Amen

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

      Truth. Great video!

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

      True, although more like ten minutes because of all the times I had to pause and rewind.

  • @cristian-e3d6m
    @cristian-e3d6m Год назад +2

    I don't know why you have so few views, the videos are pure gold

  • @carterdee7084
    @carterdee7084 Год назад +2

    I learned about utilities like 5 months ago and man… whoever keeps creating this stuff, good shit

  • @BenjaminAster
    @BenjaminAster Год назад +2

    These videos are gold and especially bullshitless. Other RUclipsrs often convey the same amount of information in a 15 minutes tutorial.

  • @Adzuraa
    @Adzuraa Год назад +2

    The whole time I was watching this I kept saying "ohhhh my god" - absolutely unreal video

  • @nather3725
    @nather3725 Год назад +13

    quickly becoming my favorite "programming tutorial" genre channel. The value to time ratio is insane

  • @rogerpantil5025
    @rogerpantil5025 9 месяцев назад +1

    u da best, no blah blah like other videos, just straight to the point with examples

  • @ManasMadrecha
    @ManasMadrecha Год назад +2

    Really awesome 👍🏻

  • @alemaolonghi
    @alemaolonghi Год назад +3

    Matt, you are the real Wizard of TS .... \,,/

  • @SpaghettiRealm
    @SpaghettiRealm Год назад +13

    Matt, your content are straight on the point and i learn more in a less time. Thank you

  • @himbary
    @himbary Год назад +2

    Nice one, I didn‘t know about Extract and NonNullable

  • @AlexTurpin
    @AlexTurpin Год назад +1

    I liked your tweet about them being the "gateway drug" to type level programming!

  • @MonoDigital
    @MonoDigital Год назад +3

    Should almost name it "TypeScript Utility Types in ", my god what this video has explained in such a short amount of time is incredible. Love the short format stuff

  • @fav8810
    @fav8810 Год назад +1

    Never looked back when I first came across TypeScript.

  • @pupfriend
    @pupfriend Год назад +3

    those tips about getting parameters and return types from external libraries is great.

    • @ColinRichardson
      @ColinRichardson Год назад +1

      Yes, I had to use `type StartOfUnitType = Parameters[0];` because standard Dayjs has a type for 'startOf' but when you add additional plugins, those plugins add additional TS types to the startOf function to make it more useful.. And it be type aware, but what they didn't do was add those additional types in an exportable way that we could reference.. So. jad to do this so our wrapper class could also reference the known types for startOf.

  • @mahmoudmohammad5595
    @mahmoudmohammad5595 Год назад +1

    The last example is what I literally did yesterday, but I didn't know any of this and I had to search for it. Thanks for the awesome video

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

    cant belive yuure a music teacher and now youre a programming teacher, life.... is so funny

  • @aundefined
    @aundefined Год назад +1

    Woah, next level video!

  • @Mitsunee_
    @Mitsunee_ Год назад +1

    love making my own utility types, like combining Pick, Omit and Partial to create SemiPartial and SemiRequired. Here's a free one for tuples:
    type FixedLengthTuple = L extends 0 ? never[] : Array & { 0: T, length: number }

  • @RodyDavis
    @RodyDavis Год назад +4

    Been using typescript for a long time and did not know about most of these! 🔥

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

    The wizard of Typescript.

  • @shinmei971
    @shinmei971 Год назад +1

    Definitely one of my favorites channels on RUclips, thanks for the great content !

  • @FredySandoval_123
    @FredySandoval_123 Год назад +1

    I'll have to watch it like 5 times

  • @IceTank
    @IceTank Год назад +1

    Thank you you TypeScript wizard. I wish I had known of these sooner.

  • @GordonChil
    @GordonChil Год назад +15

    I wish there was a plugin for my IDE that would look at what I'm doing and say "There's a built-in utility type that does this, you should use it". Because I forget about some of these

    • @lp1926.guitars
      @lp1926.guitars 9 месяцев назад

      this is where AI could help a lot. Not a copilot, but a little mentor

  • @sun33t
    @sun33t Год назад +1

    Mate, these videos are gold dust. Thanks 👍

  • @michaelhume5800
    @michaelhume5800 Год назад +3

    High quality content. I keep hearing Theo talk about letting TS infer as much as possible for scalability. Would love your take on it considering all the benefits you showcase of explicit typing.

    • @mattpocockuk
      @mattpocockuk  Год назад +1

      Absolutely - using a utility type lets you _transform_ an existing type instead of redeclaring it. For instance, UserWithoutId can be Omit.
      Inference helps keep your code DRY. This is just another kind of inference.

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

    Wow, so much information in a such short period of time,

  • @franky47
    @franky47 Год назад +1

    TIL about the `-readonly` trick to make properties mutable. Cursed syntax? Yes. Black magic? Yes. Shows decoupling between typing and runtime (Object.freeze)? Definitely: a frozen object, even marked as mutable, won't be allowed to be modified at runtime.

  • @isaacfink123
    @isaacfink123 Год назад +1

    Last week I was looking for the partial type I googled and asked chat gpt but didn't get anything, thanks for this

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

    Love this fast paced vids! ❤

  • @eulucascampelo
    @eulucascampelo Год назад +2

    One more great video on this channel... quick and useful!

  • @ColinRichardson
    @ColinRichardson Год назад +2

    Just to add, Awaited is also nest aware, so you can do `type A = Awaited;` and A will be string.

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

      Awaited correctly emulates the await keyword, which itself also recursively checks if a result in thenable (aka has a then method with compatible call signature) and uses that wait on anything PromiseLike (yes that's a type TS knows too)

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

      @@Mitsunee_ Yep, I always use PromiseLike when I am accepting a Promise as a parameter or returning the value of a method call,
      Except for an async function I will return an actual Promise

  • @rodrigopsschweitzer
    @rodrigopsschweitzer Год назад +1

    Great content! Thanks

  • @adeleke5140
    @adeleke5140 Год назад +1

    This is so useful.

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

    You are underrated, sir

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

    i will watch this video an minimum on 999 times. So mutch good information

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

    Thank you for taking the time to make these available - Sadly I missed the value of the Extract - it wasn't clear what it returned as you didn't hover over the type that was created.

    • @mattpocockuk
      @mattpocockuk  Год назад +1

      I did! At 1:45

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

      Also, thank you very much!

    • @jasonstewart7983
      @jasonstewart7983 Год назад +1

      @@mattpocockuk gotcha! thanks for the reply, Matt. It whipped by and I missed what was being examined. Cheers...

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

    with this speed you can explain whole typescript in half an hour. 👍

  • @remynijsten-rs9ce
    @remynijsten-rs9ce Год назад +1

    Thanks again Matt! Great list of useful types 😄

  • @yutamori6113
    @yutamori6113 Год назад +1

    You're absolutely incredible man :D Thanks!

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

    Great videos, i spent hours trying to grab functions parameters!

  • @techjavaid6177
    @techjavaid6177 Год назад +1

    Epic mate.
    Can you do this for the javascript series please. You're a king 👑. Easy to digest

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

    Very very wonderful and insightful🤲🏿❤️ I love these short videos, I learn faster with these instead

  • @joaolucasdossantos9
    @joaolucasdossantos9 Год назад +1

    Wow!
    Thanks!

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

    So clear and concise. Amazing

  • @JEsterCW
    @JEsterCW Год назад +1

    Wanna mention to anybody who wanna use or is using Excludes or Extracts, they're not type safety(so you can misstypo and rip), if we will try to extract something that doesn't exist or exclude we wont be notified by highlighting in editor and when i was working on my package with types i didnt know why it wasnt type safety, but then i realized why after hovering on extract and excludes. Theyre both the same, but condition is opposite, so i have made my own ones that are type safe by extending etc and they looks like this:
    *type TypeSafeExtract = T extends U ? T : never;*
    *type TypeSafeExclude = T extends U ? never : T;*
    Theyre literally doing the same, but theyre type safe, so if we're trying to do extracts or excludes like this:
    *type SomeUnion = "hey" | "hello" | "hi"*
    *type CoolType = Extract* - in this case we wont get highlights that "something" doesnt exist, but by using the type that i have made the same way what normal extract or excludes we re getting type safety
    Maybe theres a way in tsconfig to make them type safe, but couldnt find anything about it and my mate told me that its not type safe

  • @codeman99-dev
    @codeman99-dev Год назад

    2:12 You missed the primary use case: To help support developers using commonjs `export =` syntax. You can only export one type in that case.
    This really helps devs who are gradually typing a commonjs package with `module.exports =` everywhere.

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

      I definitely wouldn't say that's a primary use case! But it does sound compelling.

  • @theaungmyatmoe
    @theaungmyatmoe Год назад +1

    I would purchase your courses in very very soon

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

    This was an awesome summary! I'm interested to learn how to use utility classes with generic types. For example, if your function took a callback and you want the return type to be the result of that callback function.
    function cachedRequest (callback: F, key: string): ReturnType { ... }
    Sorry that is probably gibberish but hope that gets at the idea of what I want to do

    • @d.sherman8563
      @d.sherman8563 Год назад +1

      this works as long as you constrain type F to what ReturnType expects, the following signature works as you requested: function cachedRequest any> (callback: F, key: string): ReturnType { ... }

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

    Good content. Very useful and no BS

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

    That's a lot of information to process in under 3 minutes 🥵

  • @mdaverde
    @mdaverde Год назад +1

    It's like those peeps who are really good at niche Lodash functions but now with Typescript types

  • @djaalabahmed2038
    @djaalabahmed2038 Год назад +1

    Great my friend

  • @kasperaamodt
    @kasperaamodt Год назад +1

    Great and educational video once again!😁

  • @chiubaca
    @chiubaca Год назад +1

    So effing good

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

    Amazing, thanks

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

    This is some good stuff.

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

    Really nice and insightful video. The TS community could really use more “grand wizards” like you to help educate fledgling mages.

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

      While I agree with the sentiment I think the term ‘grand wizard’ may have been permanently ruined by a less favourable group of people

  • @harshrathod50
    @harshrathod50 Год назад +1

    Great 🔥🎉

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

    Awesome as always Matt! Are you based in London, when's your next talk? :)

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

    where is the Parameters type which you wrote on chapters

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

    this made me subscribe

  • @g3co875
    @g3co875 Год назад +1

    Great

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

    The only video I don't have to speed up

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

    Awesome.

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

    How about Nominated Omit (NOmit), where keys are known in advance

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

    Does typescript include helper functions which perform the runtime transformation of objects which mimic / match the utility types? For example, for Omit is there a similar function '_omit' from something like tslib? I think most people would use destructuring to achieve this for a simple object, but for complex nested objects it might be tricky.

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

      Nope! TypeScript doesn't see that as its job - if TS wanted to add something like that, it would need to wait for it to be available in JS first.

  • @johnlombardo
    @johnlombardo Год назад +2

    So that’s how I use NonNullable

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

    Why won’t it be ReturnType?

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

    Thanks

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

    what if you want to extract the function parameter from a library , but it has 4 functions declarations ?

  • @QCAlpha-212
    @QCAlpha-212 Год назад

    Very usefil! Is there one for arrays?

  • @CliffTech
    @CliffTech Год назад +1

    Thank you wow

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

    Thanks

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

    tysm 😃😍

  • @bs8028
    @bs8028 Год назад +1

    Great content!! Plz make this videos like 7min so I don’t have to pause😅

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

    Dang I gotta get me that course…

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

    Took me 30 minutes to finish this video

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

    Nice,

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

    what if I have one required prop in object and rest are dynamic ones?
    I tried this one:
    export interface Route {
    path: string;
    [subRoute: string]: Route;
    }
    But it gives an error: "Property 'path' of type 'string' is not assignable to 'string' index type 'Route'". How can I solve this? I need to have subRoute exactly typeof Route. I can add union like this "Route | string" but it breaks the idea of this object

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

      export type Route = {
      path: string;
      } & {
      [subRoute: string]: Route;
      }

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

      @@mattpocockuk now when I create object like this one:
      export const ROUTES: Record = {
      home: {
      path: '/',
      },
      services: {
      path: '/services',
      },
      about: {
      path: '/about',
      },
      features: {
      path: '/features',
      },
      events: {
      path: '/events',
      event: {
      path: '/events/:id',
      }
      },
      }
      It gives the error: "Type '{ path: string; }' is not assignable to type 'Route'.
      Type '{ path: string; }' is not assignable to type '{ [subRoute: string]: Route; }'.
      Property 'path' is incompatible with index signature.
      Type 'string' is not assignable to type 'Route'."

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

      @@mxrquez7692 Head to mattpocock.com/discord to get some answers - RUclips comments are awful for code feedback.

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

    Good video but you didn't talk about Record type

  • @pedrolucasdeoliveiralara8199
    @pedrolucasdeoliveiralara8199 Год назад +1

    I had built some of those by hand in my latest project, just to realize those features already existed '-' so much wasted time.

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

    woox?

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

    واو فيديو رائع

  • @Ahmed-d2o1t
    @Ahmed-d2o1t 27 дней назад

    you forgot Excludes

  • @jandresfg
    @jandresfg Год назад +1

    3 years of typescript ignorance resolved in 3 minutes. why couldnt the documentation explain like this

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

    The sound sync is a bit weird I think. Feels like a ghost talking or something.

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

    TS is amazing, i just wish the ecosystem didn't suck so much :(

  • @jemjam7297
    @jemjam7297 Год назад +1

    I'll like your YT videos since I can't like your paid content.

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

    Wtf 😳

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

    Instead of saying MaybeString, we could call it StringOrNullish.

  • @dromena
    @dromena Год назад +1

    🫀