Це відео не доступне.
Перепрошуємо.

Satisfies Operator - new TypeScript 4.9 feature!

Поділитися
Вставка
  • Опубліковано 5 сер 2024
  • Just the other day (Nov 15, 2022) TypeScript 4.9 was released! The most exciting new feature (I think) is the brand new operator: satisfies. Have you ever wanted to type check an object, but not actually change its type? Well, now you can!
    shaky.sh

КОМЕНТАРІ • 22

  • @hyperprotagonist
    @hyperprotagonist Рік тому +25

    You explain it better than the docs 😂

  • @mikedelcastillo
    @mikedelcastillo Рік тому +3

    great video as always! glad to see some coverage on this. great example too! i wish they'd have other syntax for this. something like `const config: Satisfies` or `const config: satisfies Config` just so the important bit isn't all the way at the end.

  • @hideinbush0
    @hideinbush0 Рік тому

    Such precise and helpful explanation. You are my go-to-guy for typescript.

  • @lukejagodzinski
    @lukejagodzinski Рік тому

    Imho the best explanation of satisfies that I watched/read so far. A real life example is what is needed to best explain when to use it

  • @AmirShiriAS
    @AmirShiriAS Рік тому

    Excellent explanation! Great job. I was so impressed I subscribed :)

  • @mageprometheus
    @mageprometheus Рік тому

    A great explanation of Satisfies. I can't say whether it's the best I've seen as I was 80% of the way there but it's up at the top.

  • @loko1944
    @loko1944 Рік тому

    Jesus christ I was lacking this feature for years. Its very helpful when using with typeof of this config. There was no way to create safely typed object without ruining inference to some very broad useless type. Great explanation for someone without clue of this problem

  • @Magdabo
    @Magdabo Рік тому

    OMG i love this channel

  • @pupfriend
    @pupfriend Рік тому

    awesome. love these vids. Not a second wasted.

  • @karixening
    @karixening Рік тому

    Very nice example!

  • @one_hand_claqueur
    @one_hand_claqueur Рік тому

    Nice vid, thank you!

  • @user-li7lc7pf5k
    @user-li7lc7pf5k Рік тому

    amazing explanation thank you

  • @darbyburbidge8976
    @darbyburbidge8976 Рік тому

    I guess I'm a little puzzled with whether or not you could then change tryReconnect in const config to a regular boolean and if it would show a type error within the start function's createConnection call since it's trying to call tryReconnect, which is now just a regular boolean.
    I guess this is mostly for when the data isn't expected to change, so you can write start() assuming config is a specific shape of Config (with `${port}`, and tryReconnect()).

  • @DedicatedManagers
    @DedicatedManagers Рік тому

    Fantastic example! … but at the end 5:32, what if you changed the tryReconnect on line 22 to a boolean… wouldn’t line 28 cause an error?

  • @dasten123
    @dasten123 Рік тому

    Nice! You thought of a good example instead of copying the "satisfies User" one, seen in like every other UA-cam video on this topic. Nice explanation as well!

  • @jasonhamm8809
    @jasonhamm8809 11 місяців тому

    What is the benefit of using `satisfies` instead of just typing it to the `Config` object?

  • @45g4rerf45f45
    @45g4rerf45f45 Рік тому

    Is there any reason not to use "satisfies" now?

  • @karixening
    @karixening Рік тому

    Satisfies has the same semantics as extends for generics right? Satisfies is basically just top level generics.

    • @andrew-burgess
      @andrew-burgess  Рік тому +1

      Kinda! I think of extends a little differently, since in a generic like ‘T extends User’, we know nothing about T except what we know about User, so we can only treat T as a User. Satisfies is the reverse, where the initial type is narrower than the type it satisfies.

    • @karixening
      @karixening Рік тому

      @@andrew-burgess Oh yeah, you're right. There is significant overlap, but extends would accept extra props where as satisfies would not.

  • @muhammadyasser9201
    @muhammadyasser9201 Рік тому

    the docs are using a stupid example, your code are far more clear with actually more examples in it

  • @cali4484
    @cali4484 11 місяців тому

    👎👎