how TypeScript 5.5 makes safer types in fewer keystrokes

Sdílet
Vložit
  • čas přidán 29. 08. 2024
  • TS 5.5 Announcment: devblogs.micro...
    My Links
    shaky.sh
    shaky.sh/tools
    #programming #coding #typescript #javascript
    #frontenddeveloper #backenddeveloper #softwareengineer #softwareengineering #softwaredevelopment

Komentáře • 18

  • @anon5992
    @anon5992 Před měsícem +2

    it's so refreshing to see typescript is guessing types based on what javascript will do

  • @keyserj
    @keyserj Před 2 měsíci +2

    Ooh this is quite nice to have indeed! I recently subscribed to the TypeScript devblogs, but I found myself not spending the time to read those... so I particularly appreciate the summary of the features you find useful. Cheers

  • @astrotoolau
    @astrotoolau Před 2 měsíci +2

    This is amazing! I wasn't expecting all that from v5.5, just one would have sufficed lol
    Thanks for keeping us updated :)

  • @flygonfiasco9751
    @flygonfiasco9751 Před 2 měsíci +1

    Fick Giving that predicate narrowing is such a blessing, that’s bitten me like 3 different times over the past year.

  • @edgeeffect
    @edgeeffect Před měsícem

    Oh the irony! I'm at 1:06 and I see your Typescript 5.4 workaround that I didn't know before JUST IN TIME for the 5.5 feature that I've been waiting for to come out and make it irrelevant. (kicks self)

  • @xelspeth
    @xelspeth Před 2 měsíci +2

    I'm pretty sure obj[key] is not inferred because obj[key] can change after a call even of obj and key stay the same

    • @andrew-burgess
      @andrew-burgess  Před 2 měsíci

      Hmm, how do you mean? Wouldn't that mean this new behavior can introduce bugs?

    • @xelspeth
      @xelspeth Před 2 měsíci

      @@andrew-burgess in a simple if(typeof === string) it can't (unless you use getters in which case normal variables could change, too [look up a == 1 && a == 2 && a == 3])
      But f.ex.
      if(obj[key] === 'hello') {await someLongCall(); console.log(obj[key])} could change in another function but I believe they caught that with the current implementation

    • @herrvorragend325
      @herrvorragend325 Před 9 dny

      @@andrew-burgess it can:
      function foo(obj: Record, key: string): string {
      if (typeof obj[key] === 'string') {
      bar(obj, key)
      return obj[key]
      }
      return ""
      }
      function bar(obj: Record, key: string) {
      obj[key] = 1;
      }
      typechecks in 5.5, but will return 1 as a number

  • @DavidSmith-ef4eh
    @DavidSmith-ef4eh Před 5 dny

    most languages: null is problematic, we should avoid uising it
    javascript: here is null, here is undefined, null can be undefined, undefined can be null... all goes

  • @user-vd3ph6zh8q
    @user-vd3ph6zh8q Před 2 měsíci

    Anybody ever told you, you look like Toby Maguire? Lol

  • @hugodsa89
    @hugodsa89 Před 2 dny

    wtf !!!

  • @ash1kh
    @ash1kh Před měsícem +2

    I think I will wait for typescript 9.0 when I don't have to type anything and it will be type safe. 😂😂😂😂 Telepathy compiler.

  • @AlexanderYaremchuk
    @AlexanderYaremchuk Před 2 měsíci +1

    !== null doesn't work to infer out undefined it only infers out nulls.
    last version works fine: typeof n === 'number'

    • @andrew-burgess
      @andrew-burgess  Před 2 měsíci

      Ah yep, I was specifically doing !=, which coerces undefined to null. But yeah, the typeof way is best for this one.

    • @DavidSmith-ef4eh
      @DavidSmith-ef4eh Před 5 dny

      those are ligatures, got me confused for a second there as well.