TypeScript 5.5 is a BANGER

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 มิ.ย. 2024
  • 0:00 Intro
    0:12 Regex Checking
    1:08 ${configDir}
    2:23 isolatedDeclarations
    4:35 My book!
    5:33 Type Predicate Inference
    8:17 Final Stuff
    Sign up to learn more about my upcoming book:
    www.totaltypescript.com/newsl...
    Follow Matt on Twitter
    / mattpocockuk
    Join the Discord:
    mattpocock.com/discord
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @chris94kennedy
    @chris94kennedy 9 วันที่ผ่านมา +80

    type predicate inference is just delightful.

    • @patrickkdev
      @patrickkdev 5 วันที่ผ่านมา +1

      I love that you chose the word 'delightful'. That's exactly how I feel as well!

  • @re.liable
    @re.liable 9 วันที่ผ่านมา +33

    Love the type predicate improvements. I've always considered those as unavoidable type casts.

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

      Me too - so useful.

  • @KristianTheDesigner
    @KristianTheDesigner 8 วันที่ผ่านมา +9

    Matt in a nuttshell -> ”yeah so ive been working on this really in-depth-typescript-book for a year now…it will be really helpfull..oh, btw its free”. Awesome, thanks so much for all that you do, Matt 👏

  • @theklr
    @theklr 9 วันที่ผ่านมา +19

    Congrats on the kid and the book. Glad to see so many ergonomic benefits added and the team not letting perfection be the enemy of good.

  • @palrevesz8629
    @palrevesz8629 9 วันที่ผ่านมา +4

    I Love that you are releasing the Book! ...Will definitely reach for it. You make awesome content. Thank you so much for your hard work!

  • @zach797a
    @zach797a 6 วันที่ผ่านมา

    super excited about predicates! your videos are fantastic and I always get excited when I see a new one drop!

  • @jgoon3
    @jgoon3 9 วันที่ผ่านมา +6

    100k pocock!!!! congrats!!!

  • @slowdeveloper
    @slowdeveloper 9 วันที่ผ่านมา +2

    Congrats on 100k!

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

    Thanks Matt for your video, I'm actually happy when I see your videos in the feed as I know it's not click bait low effort stuff.

  • @lengors7327
    @lengors7327 9 วันที่ผ่านมา +42

    7:38 Because 0 evaluates to false in that expression and so the predicate `x is number` would evaluate to false even though 0 is in fact a number

    • @vytah
      @vytah 6 วันที่ผ่านมา

      What Matt wants is for typescript to be able to model one-way refinements. So instead of a type that says: "true guarantees x is a number, false guarantees x is not a number", what he and other people actually would want is a type that says "true guarantees x is a number, false guaranteed nothing"

    • @osdiab
      @osdiab 3 วันที่ผ่านมา

      I think it would be reasonable to at least say that x is not null though.

    • @lengors7327
      @lengors7327 3 วันที่ผ่านมา

      ​@@osdiab how? What would the type predicate look like in that scenario?

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

      OK, but the rest are still numbers.

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

      @@crabvk A type predicate is in the form of `function (x: unknown): x is T`. In this case `T` would be `number`.
      So, if `(x) => !!x` or `Boolean` was to be used as a type predicate and that type predicate would be `function (x: unknown): x is number`, then what you are basically saying is that if `x` equals `0` then `x is number` is false, i.e. 0 is not a number, which is obviously untrue.
      So, it doesn't really matter if all others are still numbers, the type predicate would induce wrong behavior, which goes against the entire point of type inferring the type predicate.

  • @kuckuk
    @kuckuk 8 วันที่ผ่านมา +5

    Why !!member doesn't result in the desired predicate is actually explained in the release notes. Basically, the number 0 would also return false, so this predicate would be more like `member !== null && member !== 0`. The release notes say that it will work for objects tough, so !!x will correctly remove undefined / null from a union with objects.

  • @malvoliosf
    @malvoliosf 9 วันที่ผ่านมา +5

    Thanks for the book. And yes, type-guard inference solves a lot of problems for me too.

  • @benjidaniel5595
    @benjidaniel5595 9 วันที่ผ่านมา +75

    So bizarre that `Array.prototype.filter(Boolean)` still doesn’t infer array to only include truthy values. No idea why they haven’t implemented this yet given how easy it is to implement in user land

    • @ra2enjoyer708
      @ra2enjoyer708 9 วันที่ผ่านมา +6

      Passing built-ins is a pretty bad idea in the first place, just use `(value) => value` callback like all simple-minded folks do.

    • @follantic
      @follantic 9 วันที่ผ่านมา

      While I agree, I think it's a minor point. Now you can swap out `Boolean` with `it => it != null` for null+undefined checks instead of rewriting the entrie flow into loops. And you could also argue that that's more explicit. Boolean(0) === false after all.

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

      What would be the resulting inferred type (and type predicate) if the original's array type was (number | undefined)[]?

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

      There's no inference at play when doing .filter(Boolean). Boolean() is a function that happens to work like a type predicate, but it is not declared as such in the js built-in type definitions.
      Would've been nice if they did change it, but it's not such a straightforward change because of falsy numbers and strings. I can understand that it was at least out of scope.

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

      ​@@jeralmsure, but if it's Objects or Null, then there is no concern about falsy strings and numbers

  • @sudhansubhushanmishra
    @sudhansubhushanmishra 5 วันที่ผ่านมา

    Congratulations on your book; I'm really looking forward to using the regular expression validation feature

  • @ThomasBurleson
    @ThomasBurleson 8 วันที่ผ่านมา

    As usual Matt, Fantastic job! ❤🚀

  • @aram5642
    @aram5642 9 วันที่ผ่านมา

    Congrats on the 100k subs!

  • @JanisWalliser
    @JanisWalliser 8 วันที่ผ่านมา +1

    Thanks for yhe video! I really enjoy your content and was kinda sad that you stopped with the shorts format, i loved that and thats actually how i found you. Cant wait for the book and course! Count me in!!!

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

      The same here.

  • @thisweekinreact
    @thisweekinreact 5 วันที่ผ่านมา

    Great release 👌
    Indexed access type narrowing is also cool

  • @sniceone3519
    @sniceone3519 6 วันที่ผ่านมา

    Type predicate inference is just wonderful, it will save us a lot of problems. Thxs for your great video again! ;)

  • @futuremoe
    @futuremoe 9 วันที่ผ่านมา

    The website for your book looks so beautiful. Definitely gonna steal some of that.

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

    Can't state how much I've needed type predicate inference. Looking forward to this!

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

    Congrats on your baby fam!

  • @f-neto1
    @f-neto1 9 วันที่ผ่านมา

    Glad to see you back here Matt, great video! Any plans for a live stream any time soon? Looking forward to read your book as well 🎉

  • @mettle_x
    @mettle_x 9 วันที่ผ่านมา

    Congratulations on your newborn baby!

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

    Still no .filter(Boolean) 😭

    • @follantic
      @follantic 9 วันที่ผ่านมา

      sed -i 's/\.filter\(Boolean\)/.filter(it => it != null)/'
      Or something. And some thorough testing. 😀

    • @vitalysuper3193
      @vitalysuper3193 3 วันที่ผ่านมา

      There is pretty popular eslint rule that enforces Boolean instead of x=>x TypeScript team made a huge mistake not supporting popular variant (again). So it won’t be supported and typescript will be pain to use forever ;(

  • @edgeeffect
    @edgeeffect 9 วันที่ผ่านมา

    Checking your RegExs is uh-may-zing! I want that NOW!
    OOOH! And Type Predicate Inference is the feature I've been desperate for for ages... Now if the TypeScript team could just put that in to some of the other languages I use, that'd be just lovely. ;)

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

    Chrck for truthiness doesnt work because 0 is false, but zero is still a number, so its correct that it doesn't work

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

      if u do
      let val: number | undefined;
      if(!!val){
      console.log(val) // number
      } else {
      console.log(val) // number | undefined
      }
      it narrows the type down to number, so its not a limitation/consistent behaviour.

    • @DoctorGester
      @DoctorGester 6 วันที่ผ่านมา

      @@K127able it's not consistent, but, that's exactly the limitation described in the pull request, among others

  • @davidalejandrollanesbojorq63
    @davidalejandrollanesbojorq63 9 วันที่ผ่านมา

    That book will be the next TS documentation 👀👍🏼 thank you

  • @leokiller123able
    @leokiller123able 8 วันที่ผ่านมา

    Big 👍 for the free courses, not many people do that.

  • @sabinpandey
    @sabinpandey 6 วันที่ผ่านมา

    waiting for the book

  • @shapelessed
    @shapelessed 9 วันที่ผ่านมา

    To be honest, I've been using 5.5-rc for like a week or two now.
    The best features in this context are ones you don't notice, because they get out of your way.
    What did I just notice that I stopped noticing? - I don't do as much type casting. Which is delightful, because casting has a potential (however small) to mess up some of your things and waste quite a bit of your time to notice when you move on to other things.

  • @Mitsunee_
    @Mitsunee_ 9 วันที่ผ่านมา

    omg i would love named groups actually working properly in TS. I'm so tired of forcefeeding it the type when it's in theory possible to refer the group names from a pattern. Probably ended up being rather complicated to implement on their end, but I will love it every time I make use of this feature!

  • @cpakken
    @cpakken 9 วันที่ผ่านมา

    For super wizard level typescript, it would be cool if you could go over how some libraries implemnt super complex type inference like Drizzle, trpc, zod and explore TS concepts through their implementation.

    • @mattpocockuk
      @mattpocockuk  8 วันที่ผ่านมา

      That's what I do in TT!

  • @vickmackey24
    @vickmackey24 6 วันที่ผ่านมา

    Are you going to make a GPT bot out of your book so people can easily query it for information and examples?

  • @DjLeonSKennedy
    @DjLeonSKennedy 8 วันที่ผ่านมา

    you are TS god! with love from Ukraine

  • @Luxcium
    @Luxcium 8 วันที่ผ่านมา

    number has no specific trutyness but null doe this is interesting to see maybe it is one level tot complicated for having it now 😅 7:35

  • @XCanG
    @XCanG 6 วันที่ผ่านมา

    Oh yea, last one so annoying, I had to leave a smelled code to type result "as " and it's look ugly and it was not really check if it true or not (like if there is bug in the code), so it was not ideal.

  • @rhatalos1997
    @rhatalos1997 9 วันที่ผ่านมา

    So they implemented 50% of total-typescript/ts-reset. I wonder how long it's going to take for a compiler option to default to "unknown".

  • @louroboros
    @louroboros 8 วันที่ผ่านมา

    I’m not sure this is why it behaves this way, but the !!member and Boolean type predicate behavior of NOT refining the result intuitively makes sense to me, as it actually refines to a subset of the number type excluding falsey values (zero).
    Maybe one way to think about it is, if you ran this on boolean[], should it return true[]? What if you ran ran this on (true|false)[]?
    At the very least this seems like an antipattern to avoid at least for string or number since you may not want to filter out “” or 0, and thus may not be something the TS team wants to prioritize without seeing how the ecosystem reacts first.

  • @dealloc
    @dealloc 9 วันที่ผ่านมา

    I tested this a bit and got curious with the predicate inference and found something curious:
    For example, given the input [{}, null] or [{ foo: 1 }, null] and using the `!!member` expression, it results in types ({} | null)[] for the first case and ({ foo: number })[] for the second. The second is what we'd expect for the first as well.
    Not entirely sure why, since `{}` is not nullish or falsy in any way. In fact according to TypeScript itself, the _type_ of {} should represent any value except `null` and `undefined`.
    Even more fun is trying with [undefined, null], which will result in (undefined | null)[], rather than expected never[].
    I also tried with Boolean for everything, and it doesn't narrow the type at all. This is likely due to TypeScript not treating it specially (since it could be patched) and it not being an expression, but rather a constructor (TypeScript sees it as a BooleanConstructor whose constructor function returns a Boolean interface, not a type guard).

  • @hakuna_matata_hakuna
    @hakuna_matata_hakuna 6 วันที่ผ่านมา

    there is a d.ts file generation issue that's been open in tsup for months that this might fix

  • @TylerTriesTech
    @TylerTriesTech 9 วันที่ผ่านมา

    Is TotalTypeScript Essentials going to replace Beginner's TypeScript Tutorial? Or do you still recommend people with zero TypeScript experience to start with Beginner's TypeScript?

  • @ColinRichardson
    @ColinRichardson 9 วันที่ผ่านมา

    Back references are good for things like `.+?` so you are looking for a closing tag that matches the opening tag.

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

      if you're sure that there are no the same tags inside, that's okay

    • @ColinRichardson
      @ColinRichardson 9 วันที่ผ่านมา

      ​@@gooseobregex is not a tokenizer, it can only do so much.
      If you have nesting you are prob better off with a dedicated html parser. I was just showing a single example

    • @ra2enjoyer708
      @ra2enjoyer708 9 วันที่ผ่านมา

      Yeah and it's a pretty bad example.
      In general all the fancy regexp stuff dies the moment it has to deal with environment boundaries, like server and client having varying support for fancy regexp syntax. It even can be just server-side problem where two microservices support fancy regexp unevenly due to different underlying languages.
      The worst offender is ofc html with `pattern` property of `` elements, which doesn't even allow to pass custom flags and instead opts for some default implementation-dependant ones. Hope you will enjoy the meaning of the regexp changing in subtle ways between browsers and their versions.

  • @PhilipAlexanderHassialis
    @PhilipAlexanderHassialis 8 วันที่ผ่านมา

    So many great advancements to try to rectify something so bad.
    As usual, the only PROPER answer is to invent time travel and go to Brendan Eich back then and force him to put types in the flippin' language in the first place.

  • @BlurryBit
    @BlurryBit 9 วันที่ผ่านมา

    Not even 0:23 in the video but I just saw a bombshell dropping!!
    Regex type safety???!!!!?!?!?!?! aaaaaaaaaaaaaa!

  • @nomadshiba
    @nomadshiba 3 วันที่ผ่านมา

    next:
    let count = 1 // get type: 1
    count++
    count // get type 2

    • @mattpocockuk
      @mattpocockuk  3 วันที่ผ่านมา

      This works in a more useful way already:
      let a;
      a = 'abc'; // string
      a = 123; // number

  • @edgeeffect
    @edgeeffect 8 วันที่ผ่านมา

    Is there any way of having a checked `value is number`?
    Although TypeScript can now infer this, I'd still like to state it explicitly because I see explicit type information as a form of self-documenting code. It'd be great if TypeScript could report "You've asserted this value is a number - but you're checking it's a string!"

    • @mattpocockuk
      @mattpocockuk  8 วันที่ผ่านมา +1

      Sadly not! Type predicates are by default about as safe as 'as'.

  • @nicko3151
    @nicko3151 3 วันที่ผ่านมา

    I got happy for a sec until i saw that .filter(Boolean) still doesn't infer types properly

  • @rilock2435
    @rilock2435 6 วันที่ผ่านมา

    Maybe I'm wrong, but doesn't adding more inference like type predicate's go directly against what the isolated declarations need, which is less use of inferences? That seems very strange to me.

    • @mattpocockuk
      @mattpocockuk  6 วันที่ผ่านมา

      Yes, this is why isolated declarations is enabled under a flag. No reason why the rest of TS shouldn't benefit from inference.

  • @vitalysuper3193
    @vitalysuper3193 3 วันที่ผ่านมา

    Typescript 5.5 broke global type definitions in our project and we dk how to update 😢

  • @Y390R
    @Y390R 4 วันที่ผ่านมา

    seems like using regexes doesn't narrow types down either, e.g.
    const isAlphaNumeric = (input: string | undefined) =>
    input !== undefined && /^[a-z0-9]+$/i.test(input)
    won't return `input is string` but just `boolean`

    • @mattpocockuk
      @mattpocockuk  4 วันที่ผ่านมา

      Yep, that isn't in scope

  • @RomanMTino
    @RomanMTino 6 วันที่ผ่านมา

    still not working with `.filter(Boolean)` => useless release

  • @lukejagodzinski
    @lukejagodzinski 9 วันที่ผ่านมา

    The reason why !!value and Boolean don't work in this case is because !!null === !!0 and Boolean(null) === Boolean(0) so it doesn't filter non-null values but falsy values.

    • @mattpocockuk
      @mattpocockuk  8 วันที่ผ่านมา

      Sure, but !! works in if statements, so...

    • @lukejagodzinski
      @lukejagodzinski 8 วันที่ผ่านมา

      @@mattpocockuk yeah right. When I think more about it, it doesn't make sense for the !! or Boolean to not work in those cases... My bad :)

    • @lukejagodzinski
      @lukejagodzinski 8 วันที่ผ่านมา

      @@mattpocockuk also I was doing some research and look at this:
      // Does NOT work
      const y = ([0,1,2,3,null] ).filter((x) => !!x); // (number | null)[]
      // Works
      const x = ([0,1,2,3,null] as const).filter((x) => !!x); // (1 | 2 | 3)[]
      it can properly infer type when using const. I think they can improve it in the future versions. I don't think there is a reason why it shouldn't work.

  • @adamhenriksson6007
    @adamhenriksson6007 5 วันที่ผ่านมา

    I mean having tons of stuff in root_dir/dist seems a lot more preferable and sensible honestly. It seems a lot worse to have to chase down all the different build artifacts across node_modules every time you want to build from a clean slate. You kinda want your libs to be static and without artifacts. It's already a nightmare to debug dependency issues as it is.

    • @mattpocockuk
      @mattpocockuk  5 วันที่ผ่านมา

      Outputs should be colocated with their inputs, no? Your setup sounds full of implicit dependencies.

    • @adamhenriksson6007
      @adamhenriksson6007 5 วันที่ผ่านมา

      ​@@mattpocockuk An example would be an orm-plugin for a node-backend. It makes sense to create the sqlite dev file as an artifact in root. Same for plugins generating json API specs consumed by docs endpoint generators like swagger. There are probably a lot more examples.
      As far as I know there is no way for libraries to generate a npm command in root package.json which invokes cleanup for its own (or all) package.json files in node_modules. This means that state in the tree is hidden making bugs really hard to track down until all problems are mysteriously solved when dev reinstalls node_modules.
      If npm has, or implements in the future, a standardized optional cleanup command that also invokes all package cleanup commands in node_modules, this problem might be solved given that library developers implement this new convention.

  • @Pollishus
    @Pollishus 8 วันที่ผ่านมา

    i hope this doesnt mean more regex... ive seen websites that run 2m regexs on every page load eat up 5s+ of cpu bc someone at adobe decided to use all regexes to built a product

  • @adtc
    @adtc 8 วันที่ผ่านมา

    Am I the only who reads Regex as /rejeks/?

  • @adriankal
    @adriankal 8 วันที่ผ่านมา

    Dart had this type of inference 3 years ago. TŚ is lagging so much...

    • @_____case
      @_____case 6 วันที่ผ่านมา

      The more users a language has, the slower it evolves.

  • @GLObus303
    @GLObus303 5 วันที่ผ่านมา

    I think your audio does not sync with the video

  • @superduper1211
    @superduper1211 9 วันที่ผ่านมา +3

    100k Good JOB

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

    Hearing you say configDir as confirDeer instead of configDur hurt 😔😔

  • @zwanz0r
    @zwanz0r 5 วันที่ผ่านมา

    Lol. The reason why `!!maybeNumber` doesn't work is that 0 is falsy 😅

    • @mattpocockuk
      @mattpocockuk  5 วันที่ผ่านมา +1

      Lots of people are replying this, but that still means the type would be inferred correctly. It's just a subset of number instead of number. In an 'if' statement, this works. Why not trigger type predicate inference there?

    • @zwanz0r
      @zwanz0r 5 วันที่ผ่านมา

      @@mattpocockuk yeah, also figured that after responding. I think maybe because Boolean is also a constructor? There might not be a way to type that yet (a constructor with a type guard as a side effect). Not sure about !!

  • @hatsoroush23
    @hatsoroush23 6 วันที่ผ่านมา

    !! and Boolean wont work cause 0

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

    As a Rust dev I'm still unimpressed...

  • @MattChinander
    @MattChinander 9 วันที่ผ่านมา

    The lack of truthy/falsy-ness in the type predicate inference knocks down my excitement quite a bit.

  • @carlcarlinn7367
    @carlcarlinn7367 6 วันที่ผ่านมา

    7:30 does not work because !!0 is false and !!1 is true

    • @mattpocockuk
      @mattpocockuk  6 วันที่ผ่านมา

      I mean, it'll still filter to a subset of number - and this works in an 'if' statement. So I am a bit surprised that it doesn't work.

  • @greendsnow
    @greendsnow 8 วันที่ผ่านมา

    I hate typescript bureaucracy. I make copilot deal with it so my repos don't look amateurish. I hope one day we never need it.