TypeScript 5.8 Beta Sneak Peek 🤫: This New Feature is AWESOME!

  Рет қаралды 17,049

Typed Rocks

Typed Rocks

Күн бұрын

Пікірлер: 68
@ThiagoOliveiraSantosfaren
@ThiagoOliveiraSantosfaren 13 күн бұрын
I've just had to write some overloads for this exactly problem last week. That's awesome to know that this'll no longer be a problem in version 5.8!
@Typed-Rocks
@Typed-Rocks 13 күн бұрын
Awesome. I‘m also looking forward to it
@dmitryts9093
@dmitryts9093 12 күн бұрын
Could it be easier to create two types?
@ThiagoOliveiraSantosfaren
@ThiagoOliveiraSantosfaren 12 күн бұрын
@ there're plenty of scenarios where you may create a single function that returns many different types according to its parameter with no additional logic. If you have opportunity to make code simpler, typescript shines giving precise return types
@DirkLuijk
@DirkLuijk 12 күн бұрын
Finally! Been waiting for this feature for a long time. Had to depend either on overloading (which doesn’t actually check whether the implementation is consistent with the overloading contract!), or a dirty type-cast.
@malvoliosf
@malvoliosf 13 күн бұрын
This doesn’t sound like a feature so much as a bug fix. I would have thought that it would work in 5.7.
@Typed-Rocks
@Typed-Rocks 13 күн бұрын
You have to check the pullrequest. There it is explained why it wasn‘t possible before. It „kinda“ is a bug but it is explainable why it was the case.
@dzienisz
@dzienisz 12 күн бұрын
TS is mostly fixing on bugs. I think feature set was done years ago.
@keteremillpario
@keteremillpario 10 күн бұрын
Ts is a joke...
@tamirbahar
@tamirbahar 13 күн бұрын
Thanks for the video! Now I'm eagerly awaiting the 5.8 release
@Typed-Rocks
@Typed-Rocks 13 күн бұрын
Me too. Glad you like it :)
@TheCoonHouse
@TheCoonHouse 12 күн бұрын
Not sure if I understand this. Why wouldn't you create separate types for "PersonType" and "CompanyType"? What's the benefit of doing it this way?
@Betadesk
@Betadesk 12 күн бұрын
Just to flex some TypeScript magic
@Typed-Rocks
@Typed-Rocks 11 күн бұрын
I wanted to use a similar example as in the pull request where it was merged to make it easier for the reader of the pr to understand.
@TheCoonHouse
@TheCoonHouse 10 күн бұрын
@@Typed-Rocks Could you give an example of where this would be useful? Always willing to learn.
@rajikkali
@rajikkali 10 күн бұрын
Yeah, looks like bad coding practice to me too
@benny123tw
@benny123tw 5 күн бұрын
Well explain!
@LostZenith_
@LostZenith_ 12 күн бұрын
I don't know about write less code, but it's definately a lot more readable. Excellent change indeed!
@Typed-Rocks
@Typed-Rocks 12 күн бұрын
Absolutely. The thing aber better readability is always a plus
@arthurtweak3801
@arthurtweak3801 7 күн бұрын
Omg 🚀
@EmilyK92345
@EmilyK92345 12 күн бұрын
type UserType = { person: { firstname: string; lastname: string }; company: { name: string }; }; function mockUser(type: T): UserType[T] { const mockData: { [K in keyof UserType]: UserType[K] } = { person: { firstname: "John", lastname: "Doe" }, company: { name: "Apple" }, }; return mockData[type]; } const personMock = mockUser("person"); const companyMock = mockUser("company"); compiled in 5.7 without overloads
@gdgdgdgdgdgdgdgd
@gdgdgdgdgdgdgdgd 12 күн бұрын
works even without that mapped type annotation in const mockData
@mikuhl
@mikuhl 12 күн бұрын
This is not a great solution for performance sensitive applications.
@Krmpfpks
@Krmpfpks 10 күн бұрын
@@mikuhli doubt that it is slower in any JS runtime, they all will optimize that out.
@eliuddyn
@eliuddyn 12 күн бұрын
Amazing 🔥🔥
@Typed-Rocks
@Typed-Rocks 12 күн бұрын
Thanks 🔥
@thechoephix
@thechoephix 12 күн бұрын
Finally!
@zeratax
@zeratax 6 күн бұрын
this was one of my biggest issues with typescript tbh
@jon1867
@jon1867 12 күн бұрын
This is super nice!
@Typed-Rocks
@Typed-Rocks 12 күн бұрын
Glad you like it!
@pookiepats
@pookiepats 11 күн бұрын
When your Linter gets a cool new feature
@coder_one
@coder_one 5 күн бұрын
In all these years of commercial work, I have not missed this feature. What are its actual real world use cases (not so trivial like mocking data)?
@Typed-Rocks
@Typed-Rocks 5 күн бұрын
Often it's for library authors. In a normal codebase you rarely need these advanced types. That's 100% true.
@thejimmylin
@thejimmylin 6 күн бұрын
What is the nice // ^? feature from?
@Typed-Rocks
@Typed-Rocks 6 күн бұрын
Its from a plugin called „twoslash-queries“
@thejimmylin
@thejimmylin 6 күн бұрын
@@Typed-RocksThank you so much!😊
@meuscc
@meuscc 13 күн бұрын
need partial type inference and pipe operator
@Typed-Rocks
@Typed-Rocks 13 күн бұрын
Maybe in the future
@moh6823
@moh6823 12 күн бұрын
You can just use keyof instead of overloading the function. It would result in the same code?
@Typed-Rocks
@Typed-Rocks 12 күн бұрын
In the final one, this is true 👍. But we don‘t need that anymore with 5.8
@darkerisbetter8699
@darkerisbetter8699 13 күн бұрын
I’ve wanted this feature to narrow arrays. The overload style is gross (though I have used it).
@Typed-Rocks
@Typed-Rocks 13 күн бұрын
I agree. The new approach is really nice and concise 🤘
@ErnaSolbergXXX
@ErnaSolbergXXX 10 күн бұрын
This just seems like one more way to create a messy code base with typescript.
@giovanesouza8664
@giovanesouza8664 8 күн бұрын
JS devs got types and now they do this with them... Why?
@taquanminhlong
@taquanminhlong 12 күн бұрын
Good to see typescript being less dump 😂
@SaurabhSrivastava-i1q
@SaurabhSrivastava-i1q 10 күн бұрын
I am not writing types which has become another programming language itself!
@tesilab994
@tesilab994 10 күн бұрын
How very strange to illustrate this example with a "UserType" which isn't really a type, but just a holder for unrelated types each with its own property name. The example would be better if your property names were capitalized, and each one independently defined as a type, and then you combined them into so a union.
@zohnannor
@zohnannor 12 күн бұрын
bro, please, increase the bitrate when exporting/recording the video. your videos are great, but all those artifacts ruin the experience!
@Typed-Rocks
@Typed-Rocks 12 күн бұрын
Interesting. Are you watching it on a pc? I‘m exporting it with h.264 from final cut as mp4. Sometimes KZbin does scale it down :(
@zohnannor
@zohnannor 12 күн бұрын
@@Typed-Rocks yeah, I'm on pc, watching in 1080p. I constantly see those "flashing rectangles" of artifacts, and the edge of the circle of your webcam is very blurry hard to see :( I don't really know how to describe the artifacts lol
@pantherofsteel
@pantherofsteel 9 күн бұрын
Being so much excited for TS is one of the saddest things that I saw on internet today.
@Typed-Rocks
@Typed-Rocks 9 күн бұрын
Then you must have an awesome curated internet feed 🤘
@cenkakay3506
@cenkakay3506 11 күн бұрын
yeah switch case really messy
@dzienisz
@dzienisz 12 күн бұрын
TypeScript is the most complicated thing in JS world. I just personally hate it.
@Typed-Rocks
@Typed-Rocks 12 күн бұрын
Sad to hear. But I can understand
@Betadesk
@Betadesk 12 күн бұрын
Yeah I believe the type system is Turing complete lmao, but just cause it can be complicated doesnt mean it has to be. For example you could easily just make a mockPerson() and mockCompany() function whose types are straightforward
@coder_one
@coder_one 11 күн бұрын
@dzienisz perhaps jsDoc?
@hugodsa89
@hugodsa89 12 күн бұрын
Dude instead of overloading you could do an XOR
@LordErnie
@LordErnie 12 күн бұрын
Although I love TypeScript, these are the moments where I think its just still lacking. Really with all of the different ways we can use typing in TypeScript I'd imagine this would be a base feature in the first place.
@Typed-Rocks
@Typed-Rocks 12 күн бұрын
I was also expecting that but the language is always evolving.
@ShinSpiegel
@ShinSpiegel 12 күн бұрын
Unpopular opinion, the new code look uglier.
@Typed-Rocks
@Typed-Rocks 12 күн бұрын
Maybe for this simple case. But if you have more cases, the overloading would be quite repetitive. But everyone to their likings
@ShinSpiegel
@ShinSpiegel 12 күн бұрын
@ repetitive, yes. But also expressive. It shows what expect, generics on this level makes the code “unpredictable” since it depends on other types (that can or cannot exist closer) to the function. Either way, it was already a unpopular opinion.
@userasd360
@userasd360 12 күн бұрын
type UserType = { person: { firstName: string; lastName: string }; company: { name: string }; }; function mockUser(type: T): UserType[T] { switch (type) { case "person": return { firstName: "John", lastName: "Doe" } as UserType[T]; case "company": return { name: "ACME" } as UserType[T]; default: return undefined as unknown as UserType[T]; } } Just for the return type to match each return is forcefully type casted to that return type or need to create overloaded functions for the same as suggested by you.
@Typed-Rocks
@Typed-Rocks 12 күн бұрын
Also a great way👍
@airman122469
@airman122469 11 күн бұрын
Until TypeScript has strict TYPES, I really couldn’t give less of a shit about its other features.
@Typed-Rocks
@Typed-Rocks 10 күн бұрын
I don‘t think we will ever have this :(
Bulletproof Builder Pattern in TS
7:20
Andrew Burgess
Рет қаралды 10 М.
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
as const: the most underrated TypeScript feature
5:38
Matt Pocock
Рет қаралды 129 М.
A cool way to do reflection in javascript
8:15
mcsamr
Рет қаралды 5 М.
Javascript's New Pipeline Operator Is Awesome!
7:26
Jack Herrington
Рет қаралды 45 М.
Why is every React site so slow?
13:52
Theo - t3․gg
Рет қаралды 132 М.
This free Chinese AI just crushed OpenAI's $200 o1 model...
4:41
Don't put your types in .d.ts files
3:54
Matt Pocock
Рет қаралды 145 М.
Stop Using Pixels For Media Queries
18:48
Web Dev Simplified
Рет қаралды 58 М.
some of the worst API security i've EVER seen
27:53
Low Level
Рет қаралды 360 М.
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН