TypeScript 5.5 is a BANGER

  Рет қаралды 56,351

Matt Pocock

Matt Pocock

Күн бұрын

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 8 күн бұрын
type predicate inference is just delightful.
@patrickkdev
@patrickkdev 4 күн бұрын
I love that you chose the word 'delightful'. That's exactly how I feel as well!
@re.liable
@re.liable 8 күн бұрын
Love the type predicate improvements. I've always considered those as unavoidable type casts.
@mattpocockuk
@mattpocockuk 8 күн бұрын
Me too - so useful.
@KristianTheDesigner
@KristianTheDesigner 7 күн бұрын
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 8 күн бұрын
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 8 күн бұрын
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 5 күн бұрын
super excited about predicates! your videos are fantastic and I always get excited when I see a new one drop!
@jgoon3
@jgoon3 8 күн бұрын
100k pocock!!!! congrats!!!
@slowdeveloper
@slowdeveloper 8 күн бұрын
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 8 күн бұрын
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 2 күн бұрын
​@@osdiab how? What would the type predicate look like in that scenario?
@crabvk
@crabvk Күн бұрын
OK, but the rest are still numbers.
@lengors7327
@lengors7327 Күн бұрын
@@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 7 күн бұрын
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 8 күн бұрын
Thanks for the book. And yes, type-guard inference solves a lot of problems for me too.
@benjidaniel5595
@benjidaniel5595 8 күн бұрын
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 8 күн бұрын
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 8 күн бұрын
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 8 күн бұрын
What would be the resulting inferred type (and type predicate) if the original's array type was (number | undefined)[]?
@jeralm
@jeralm 8 күн бұрын
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 8 күн бұрын
​@@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 7 күн бұрын
As usual Matt, Fantastic job! ❤🚀
@aram5642
@aram5642 8 күн бұрын
Congrats on the 100k subs!
@JanisWalliser
@JanisWalliser 7 күн бұрын
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 4 күн бұрын
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 8 күн бұрын
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 6 күн бұрын
Congrats on your baby fam!
@f-neto1
@f-neto1 8 күн бұрын
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 8 күн бұрын
Congratulations on your newborn baby!
@dominikrodler8010
@dominikrodler8010 8 күн бұрын
Still no .filter(Boolean) 😭
@follantic
@follantic 8 күн бұрын
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 8 күн бұрын
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 8 күн бұрын
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 6 күн бұрын
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 5 күн бұрын
@@K127able it's not consistent, but, that's exactly the limitation described in the pull request, among others
@davidalejandrollanesbojorq63
@davidalejandrollanesbojorq63 8 күн бұрын
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 5 күн бұрын
waiting for the book
@shapelessed
@shapelessed 8 күн бұрын
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_ 8 күн бұрын
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 8 күн бұрын
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 7 күн бұрын
you are TS god! with love from Ukraine
@Luxcium
@Luxcium 7 күн бұрын
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 8 күн бұрын
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 8 күн бұрын
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 5 күн бұрын
there is a d.ts file generation issue that's been open in tsup for months that this might fix
@TylerTriesTech
@TylerTriesTech 8 күн бұрын
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 8 күн бұрын
Back references are good for things like `.+?` so you are looking for a closing tag that matches the opening tag.
@gooseob
@gooseob 8 күн бұрын
if you're sure that there are no the same tags inside, that's okay
@ColinRichardson
@ColinRichardson 8 күн бұрын
​@@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 8 күн бұрын
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 8 күн бұрын
Not even 0:23 in the video but I just saw a bombshell dropping!! Regex type safety???!!!!?!?!?!?! aaaaaaaaaaaaaa!
@nomadshiba
@nomadshiba 2 күн бұрын
next: let count = 1 // get type: 1 count++ count // get type 2
@mattpocockuk
@mattpocockuk 2 күн бұрын
This works in a more useful way already: let a; a = 'abc'; // string a = 123; // number
@edgeeffect
@edgeeffect 7 күн бұрын
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 7 күн бұрын
Sadly not! Type predicates are by default about as safe as 'as'.
@nicko3151
@nicko3151 2 күн бұрын
I got happy for a sec until i saw that .filter(Boolean) still doesn't infer types properly
@rilock2435
@rilock2435 5 күн бұрын
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 5 күн бұрын
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 3 күн бұрын
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 3 күн бұрын
Yep, that isn't in scope
@RomanMTino
@RomanMTino 5 күн бұрын
still not working with `.filter(Boolean)` => useless release
@lukejagodzinski
@lukejagodzinski 8 күн бұрын
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 7 күн бұрын
@@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 7 күн бұрын
@@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 4 күн бұрын
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 4 күн бұрын
Outputs should be colocated with their inputs, no? Your setup sounds full of implicit dependencies.
@adamhenriksson6007
@adamhenriksson6007 4 күн бұрын
​@@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 7 күн бұрын
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 7 күн бұрын
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 5 күн бұрын
The more users a language has, the slower it evolves.
@GLObus303
@GLObus303 4 күн бұрын
I think your audio does not sync with the video
@superduper1211
@superduper1211 8 күн бұрын
100k Good JOB
@dhkatz_
@dhkatz_ 6 күн бұрын
Hearing you say configDir as confirDeer instead of configDur hurt 😔😔
@zwanz0r
@zwanz0r 4 күн бұрын
Lol. The reason why `!!maybeNumber` doesn't work is that 0 is falsy 😅
@mattpocockuk
@mattpocockuk 4 күн бұрын
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 4 күн бұрын
@@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 8 күн бұрын
The lack of truthy/falsy-ness in the type predicate inference knocks down my excitement quite a bit.
@carlcarlinn7367
@carlcarlinn7367 5 күн бұрын
7:30 does not work because !!0 is false and !!1 is true
@mattpocockuk
@mattpocockuk 5 күн бұрын
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 7 күн бұрын
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.
8 TypeScript Tips To Expand Your Mind (and improve your code)
10:54
Generics: The most intimidating TypeScript feature
18:19
Matt Pocock
Рет қаралды 164 М.
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 89 МЛН
터키아이스크림🇹🇷🍦Turkish ice cream #funny #shorts
00:26
Byungari 병아리언니
Рет қаралды 27 МЛН
as const: the most underrated TypeScript feature
5:38
Matt Pocock
Рет қаралды 111 М.
Why Is C SO Dangerous?  #programming #coding #lowcode
0:51
Low Level Learning
Рет қаралды 1,9 МЛН
Turborepo 2 0
6:09
Anthony Shew
Рет қаралды 1,4 М.
How Big Tech Ships Code to Production
0:59
ByteByteGo
Рет қаралды 276 М.
Cool Tools I’ve Been Using Lately
23:11
Theo - t3․gg
Рет қаралды 186 М.
Why Does Scrum Make Programmers HATE Coding?
16:14
Thriving Technologist
Рет қаралды 497 М.
Nesting "If Statements" Is Bad. Do This Instead.
1:00
Flutter Mapp
Рет қаралды 3,6 МЛН
TypeScript Generics are EASY once you know this
22:21
ByteGrad
Рет қаралды 125 М.
The Weirdest Language I've Ever Seen (I kinda love it...)
58:11
Theo - t3․gg
Рет қаралды 40 М.
The Story of React Query
8:55
uidotdev
Рет қаралды 90 М.
CY Superb Earphone 👌 For Smartphone Handset
0:42
Tech Official
Рет қаралды 826 М.
Main filter..
0:15
CikoYt
Рет қаралды 12 МЛН
Samsung S24 Ultra professional shooting kit #shorts
0:12
Photographer Army
Рет қаралды 34 МЛН