TypeScript 5.3 First Look

  Рет қаралды 40,837

Matt Pocock

Matt Pocock

Күн бұрын

TypeScript 5.3 is coming, and today we got the first hints on what it might contain. Here's the full breakdown!
00:00 Intro
00:20 Import Attributes
01:23 Throw Expressions
02:13 Isolated Declarations
03:39 Narrowing in Generic Functions
04:33 Loose Autocomplete
05:10 Fetch in Node
05:38 Outro
Full article: www.totaltypescript.com/types...
Become a TypeScript Wizard with my free beginners TypeScript Course:
www.totaltypescript.com/tutor...
Follow Matt on Twitter
/ mattpocockuk
Join the Discord:
mattpocock.com/discord

Пікірлер: 79
@jacoblockwood4034
@jacoblockwood4034 10 ай бұрын
Ideas for your TypeScript book: - Teach the TSConfig well with sensible defaults - Mention the annoying caveats with React, etc and how to deal with them. - Idea for a more advanced exercise, maybe for near the end of the book: "Try to implement a Repeat that outputs TString repeated TNum times."
@mattpocockuk
@mattpocockuk 10 ай бұрын
TSConfig is definitely in there. Caveats with React are in my React module on TT.
@joaofrancisco5781
@joaofrancisco5781 10 ай бұрын
​@@mattpocockuk Thanks, I'll watch those modules, awesome
@glorrin
@glorrin 10 ай бұрын
The one thing I am realy excited about is fetch XD But one thing I would love typescript to add is strongly typed throw errors
@ColinRichardson
@ColinRichardson 10 ай бұрын
Think my fav with all this is the throw expression
@svenyboyyt2304
@svenyboyyt2304 10 ай бұрын
I hope you can also do return, yield, continue and break in the same way.
@emmanuelmahuni8163
@emmanuelmahuni8163 10 ай бұрын
I actually used this expression a lot in regualar js some time back before using ts. When moved code to ts, it gave me that exact error. I was perplexed and just thought maybe there's something i m not aware of that this messes up since I never saw it used anywhere and had to refactor code. 😅 happy to see ts catching up on this.
@ColinRichardson
@ColinRichardson 10 ай бұрын
@@emmanuelmahuni8163 it's not that TS is catching up.. It's NEVER been possible in JS (and currently still isn't).. You may have wrote the code, but trust me, it wasn't working..
@cristobalcontrerasrubio4695
@cristobalcontrerasrubio4695 10 ай бұрын
I'm really glad to discover you. Thanks to you Matt I'm improving a lot 👍👍👍
@chstappert
@chstappert 10 ай бұрын
Thanks for this summary. Looking forward to work with 5.3
@sillvvasensei
@sillvvasensei 10 ай бұрын
Really excited about the narrowing
@devinsights8021
@devinsights8021 10 ай бұрын
Great work 🎉
@keelangibb565
@keelangibb565 2 ай бұрын
For anyone running into the @typescript-eslint/ban-types: Don't use `{}` as a type. `{}` actually means "any non-nullish value" problem. You can get around this error by doing this instead. type IconSize = "small" | "medium" | "large" | (string & NonNullable); This strips undefined and null from unknown which leaves you with {}, This is equivalent to the code in the video but you no longer have to disable the rule in your editor. Hope that helps :)
@user-yz2mv8kn4x
@user-yz2mv8kn4x 10 ай бұрын
great informative video, looking forward to your TS book :)
@pupfriend
@pupfriend 10 ай бұрын
this was worth the watch just to see some of those hacks!
@karamuto1565
@karamuto1565 10 ай бұрын
I would like to have "throws" declarations in typescript. This way we could better describe functions that should have a try / catch block around their call.
@mattpocockuk
@mattpocockuk 10 ай бұрын
This won't be added, for many reasons - should record a video about this.
@barneylaurance1865
@barneylaurance1865 10 ай бұрын
Similar to checked exceptions in Java. Possibly one of the most complained about features of Java though. I remember Phpstan has an interesting approach to it.
@schwarkof
@schwarkof 10 ай бұрын
Doesn’t this kind of go against the pattern of functional programming? Not to say that’s really at play here, but feels like this new “throws” declaration leans back towards the classic try/catch style of code.
@karamuto1565
@karamuto1565 10 ай бұрын
@@mattpocockuk I will look forward to it. That there is currently no way of telling that a function can error is one of the biggest downfalls of JS and TS doesn't provide any improvement here.
@karamuto1565
@karamuto1565 10 ай бұрын
@@barneylaurance1865 I rather have some way of telling a function errors then none. Uncatched errors are a nightmare in JS/TS.
@MrGVSV
@MrGVSV 10 ай бұрын
Interesting to hear about that string union trick. Might be IDE specific, since I’ve just done `| string` before and WebStorm autocompletes just fine
@karamuto1565
@karamuto1565 10 ай бұрын
I guess that's because Webstorm adds some of their own stuff on top of the default language service. They just recently included their own version of the "pretty-ts-errors" lib into the thing and it's already pretty good.
@normanaranez323
@normanaranez323 10 ай бұрын
Hi Matt, can you also check prisma on how we can create props base on the prisma setup, that would be great too 😊
@emilbeothy5152
@emilbeothy5152 10 ай бұрын
Even cooler than throw expression would be return expression. The throw case can already kind of achieved by wrapping it in a function, but with return that is not possible.
@a-yon_n
@a-yon_n 10 ай бұрын
I hope they allow import statements with extentions
@maxilkiv
@maxilkiv 10 ай бұрын
can't stop the TS-train 🔥🔥🗣🗣🗣🗣
@maxijonson
@maxijonson 10 ай бұрын
throw expression and (string & {}) 👌👌👌👌👌
@Dev-Siri
@Dev-Siri 10 ай бұрын
they substituted the previously deprecated with keyword for import-type-assertions???
@mattpocockuk
@mattpocockuk 10 ай бұрын
The proposal changed from assertions to attributes.
@developerpranav
@developerpranav 10 ай бұрын
autocomplete for "| string" lets go!!
@s_gryt
@s_gryt 10 ай бұрын
Well, the autocomplete is indeed a cool feature. Linter has always been pissed about an intersection type with a {} 💩
@lil_peepka
@lil_peepka 10 ай бұрын
Let em ship
@s_gryt
@s_gryt 10 ай бұрын
I’d rather have nullish coalescing throw. It is way obvious in null pointer context: (example): null ?? throw new Error(‘…’);
@mattpocockuk
@mattpocockuk 10 ай бұрын
Once this proposal lands, you can also have nullish coalescing throw, or throw in a ternary.
@SexyBeast4444
@SexyBeast4444 10 ай бұрын
Don't really get import attributes. If the argument is security, then you could have a compiler flag that checks if the extension that you are trying to import is actually what it claims to be. If the counter argument to this is that you want to do it selectively, then something like: import json from './foo.json' with check; would be more clear. But I guess this gives freedom to import any extension and check for any extension at the cost of boilerplate.
@SamualN
@SamualN 10 ай бұрын
import attributes are part of javascript not typescript so there's no compiler checks. and in web land, extensions don't determine types, mime types do so a foo.json could resolve to a javascript module with a javascript mime type
@parlor3115
@parlor3115 10 ай бұрын
I don't understand the IconSize example. If you want other values, then why not include them in the union?
@mattpocockuk
@mattpocockuk 10 ай бұрын
You want _arbitrary_ values, like '10px' or something.
@karamuto1565
@karamuto1565 10 ай бұрын
It's kind of an auto complete for the members but you can still assign any other string. This is useful if you don't know all members or it's just not worth to have all of them.
@parlor3115
@parlor3115 10 ай бұрын
@@mattpocockuk I guess this is a old issue because now it's fixed with template literal types.
@shapelessed
@shapelessed 10 ай бұрын
Finally they fixed throwing errors in conditional statements...
@Mitsunee_
@Mitsunee_ 10 ай бұрын
Oh they are fixing the string autocomplete thing? I have a lint rule that disallows using {}, so I guess the eslint disable comment there is now officially temporary :)
@ThEldeRS
@ThEldeRS 10 ай бұрын
#NotSoHotTake: Errors as value > Throwing. The fact that you can't know if a function is going to throw or not and the inconsistency in the "standard" library are incredibly frustrating! Return an error type like Go and Rust, have strong prototypes like the Option or Result in Rust, either way would be 100 times better than throwing errors.
@patfre
@patfre 10 ай бұрын
Nice but can browsers finally start allowing import json?
@patfre
@patfre 10 ай бұрын
@@codernerd7076 well Apple is one of the companies who already do support it. Firefox and Opera are the only ones that do not. Safari has done since IOS 15 or ALMOST 2 YEARS and you say they are fighting against it, brainwashed person
@DisturbedNeo
@DisturbedNeo 10 ай бұрын
Not personally a fan of the proposal for imports. If you give developers the option, most won't use it and the rest will probably use it wrong. Since there's no reason I know of to ever import, for example, JSON with type Javascript, only ever with type JSON, just infer the "with" type based on the file extension and do the security check behind the scenes. And with that, you just automatically boosted the security of every Typescript application from 5.3 onwards without any developer needing to do anything different. _That_ would be a good change.
@LongNguyen-dh3bm
@LongNguyen-dh3bm 10 ай бұрын
This is not because people "make a JSON file that has JS in it", it's to ensure that the code will only accept JSON from the server, so a malicious actor can't swap out the content of a JSON file with something else.
@brangtoggez6363
@brangtoggez6363 10 ай бұрын
Has anybody tried Matt's courses ? On Reddit people disliked his courses a lot since it's pricey and don't teach much, all he did was just giving problems that will never be appeared in real life or anything like that ? I am confused here. His content on youtube is too good to even believe that.
@mattpocockuk
@mattpocockuk 10 ай бұрын
The free tutorials should give you a taste! www.totaltypescript.com/tutorials
@brangtoggez6363
@brangtoggez6363 10 ай бұрын
@@mattpocockuk Thanks, I'll give it a try. Please excuse me if I say anything that can make you sad, it's just pretty pricey for asians like me so I have to consider. again thanks!
@mattpocockuk
@mattpocockuk 10 ай бұрын
@@brangtoggez6363 No worries pal, it's absolutely an investment. It's ideally designed for your work to pay with an education budget.
@QwDragon
@QwDragon 10 ай бұрын
Any problem sometime will ocur in real life.
@symix.
@symix. 10 ай бұрын
I feel like people who have hard time with "problems that will never appear in real life" just dont understand generalization / abstraction (or are not aware of it), like if you learn to solve problem X, and you need to solve Z, your mind could get to answer using parts of X (and you wont even necessarily know your brains did that, they can do lot of stuff on the background)
@jacoblockwood4034
@jacoblockwood4034 10 ай бұрын
Well, the updates start shippin' and they don't stop shippin'…
@markzuckerbread1865
@markzuckerbread1865 10 ай бұрын
Throw expressions are very weird, an expression whose value is never used and one that only exists for its side effects? weird imo.
@joshuakb2
@joshuakb2 10 ай бұрын
It's an expression whose type is never, which makes sense because the expression never evaluates to anything. It would be very handy to use a `throw` expression as the default at the end of a long chain of optionals, like this: type X = null | { y?: { z?: string } }; const f = (x: X): string => x?.y?.z ?? throw new Error('Cannot get x.y.z');
@barneylaurance1865
@barneylaurance1865 10 ай бұрын
It was implemented in PHP 8.0, which came out in 2020. Maybe a little weird, but very useful and I can't see any reason not to have it.
@danielschwartz516
@danielschwartz516 10 ай бұрын
string & {} 🤯
@somegaydog
@somegaydog 10 ай бұрын
Needing to include the dom lib types just to use native fetch has always been really annoying
@PaulSebastianM
@PaulSebastianM 10 ай бұрын
They need to simplify TS, not make it more complicated... unless it increases DX and developer ergonomics.
@philheathslegalteam
@philheathslegalteam 10 ай бұрын
Thats exactly what theyre doing here lol.
@PaulSebastianM
@PaulSebastianM 10 ай бұрын
@@philheathslegalteam not so sure...
@samarbid13
@samarbid13 10 ай бұрын
I think Next version should be: Integrating TypeScript with Copilot marks a new era where AI handles type management, freeing developers for more innovative tasks. Let's redefine our workflow, making types the domain of AI, and elevate creativity for developers! it's 2023!
@user-fr2fm3ri3w
@user-fr2fm3ri3w 10 ай бұрын
Actually the opposite if you don’t have an interface copilot has a stroke and even tried to divide by 0 and such
@codernerd7076
@codernerd7076 10 ай бұрын
Typescript moving too far ahead from Javascript the main function is types. But they now act like it's their language and trying to force Javascript features to be added.
@ColinRichardson
@ColinRichardson 10 ай бұрын
I can live with that. It acts like a polyfill until JS catches up. The fact that you can write obj.with?.optional.props and then tell TS to output valid es5 with a bunch of `(_a = obj.with) === null || _a === void 0 ? void 0 : _a.optional.props` to make it work.. LOVE IT.. And TS being the forerunner means they can just polyfill until JS catches up in like ES2045 or what ever.
@PatricioHondagneuRoig
@PatricioHondagneuRoig 10 ай бұрын
And I wouldn't mind that one bit!
@rnz2363
@rnz2363 10 ай бұрын
exceptions as an expression ? i hope this never happens. you either deal with exceptions, which is a side effect, or with errors as value, but why mix both ? i think this is really stupid and yet another pile of junk on top of javascript.
@user-fr2fm3ri3w
@user-fr2fm3ri3w 10 ай бұрын
Imagine thinking JavaScript of all things in the planet is perfect and needs no changed in top of it to make it bearable 🥶
@CoentraDZ
@CoentraDZ 10 ай бұрын
“Type”Script taking types too seriously
@BinaryReader
@BinaryReader 10 ай бұрын
Throw Expressions would be amazing...you can have them today with..... const X = Y || (() => { throw Error('nope') })()
@s_gryt
@s_gryt 10 ай бұрын
Posted a comment above about nullish coalescing throw (imo, would look more obvious) const { x } = obj ?? throw new Error() or const x = obj.x ?? throw new Error()
Infer is easier than you think
13:38
Matt Pocock
Рет қаралды 86 М.
TypeScript 5.3 что в релизе?
12:17
PurpleSchool | Anton Larichev
Рет қаралды 8 М.
She ruined my dominos! 😭 Cool train tool helps me #gadget
00:40
Go Gizmo!
Рет қаралды 60 МЛН
когда повзрослела // EVA mash
00:40
EVA mash
Рет қаралды 2,7 МЛН
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,4 МЛН
This TS naming convention is weird
4:01
Matt Pocock
Рет қаралды 116 М.
This Should Have Been In CSS Years Ago
1:57
Dev Dive In
Рет қаралды 33 М.
Most TS devs don't understand 'satisfies'
4:10
Matt Pocock
Рет қаралды 53 М.
TypeScript: Should you use Types or Interfaces?
4:06
Matt Pocock
Рет қаралды 149 М.
New Keyword "using" in JavaScript!
11:30
ThePrimeTime
Рет қаралды 82 М.
Getting A Tech Job In 2023
10:54
Theo - t3․gg
Рет қаралды 186 М.
TypeScript Performance with Aleksandra Sikora
1:05:02
Matt Pocock
Рет қаралды 16 М.
How To Unlock Your iphone With Your Voice
0:34
요루퐁 yorupong
Рет қаралды 28 МЛН