Satisfies Operator - new TypeScript 4.9 feature!

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

ความคิดเห็น • 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.

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

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

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

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

  • @45g4rerf45f45
    @45g4rerf45f45 ปีที่แล้ว

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

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

    OMG i love this channel

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

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

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

    👎👎

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

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

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

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

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

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

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

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

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

  • @허바드제이콥
    @허바드제이콥 ปีที่แล้ว

    amazing explanation thank you

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

    awesome. love these vids. Not a second wasted.

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

    Nice vid, thank you!

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

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

    Very nice example!