7 Awesome TypeScript Types You Should Know
HTML-код
- Опубликовано: 14 сен 2023
- These have saved me so much time in building out my apps, so I thought I'd share them with you. Hopefully they'll save you just as much time and nerves instead of figuring out all this yourself lol.
Matt Pocock explaining the Prettify Type: • Prettify for Classes
-- my links
Next.js SaaS: www.splitter.gg/
Discord: / discord
GitHub: github.com/joschan21 Наука
Another Typescript type, which is not included in the video, is the Pick type, which is the opposite of Omit. Instead of Omitting the property, you include the properties to be picked.
I'll always appreciate these TS videos any day of the week
Man, there's a LOT of information in here I never even heard of, but is pretty much exactly what I need, super cool. This would be a great video to add chapters to btw:
0:00 Intro
0:18 typeof / keyof
1:21 ReturnType / Awaited
2:59 Prettify (and nesting)
4:07 Partial / Required
5:58 Omit / Exclude
The Prettify type should not exist. It should be a typescript configuration option.
it is good until you are really need to have an object
The semantics of what the higher level types are defined as is relevant information.
The exclude util is not necessarily used for more complex types. It's for excluding types from union types in general instead of omitting props from an object type. So you could also use it to exclude e. g. string literals
Great stuff Josh! Please never stop posting new content!
updateTodo example has a bug... you need to prefix fieldsToUpdate with ... if you want to override the todo, otherwise you will create an object with additional fieldsToUpdate property, which contains the values that should be used for updating.
Great explanations, very well illustrated. Thanks
We need more videos like these!! Great video buddy
Fantastic video, simple, well explained and to the point. Great examples 👍
Wow! These are good TypeScript tips. Thank you!
Really nice, short but with so many good and important things video.
These are super cool tips. Thank you for sharing them
thanks a lot , we are constantly learning from your videos ! ,keep going
I'll never understand why interfaces hide their fields like it's something shameful lol. That Prettify type will save millions of developers including me.
Bc it’s and interface 😂 not and object…
Javascripters trying to understand object orientation.
It used to be that way. But people complained that it is confusing and convoluted to see the result of the union when a union of preexisting types is made, instead they wanted to see which types the union is made of.
@@Netrole what hellll. i think would be pretty usefull show the type and your fields.
Like:
title: string;
description: string;
role: Role <
{ name: string, i
id: number }
>
it is useful in creating branded type
One of the rare examples where a rather clickbaity sounding video really delivers 👍
great stuff Josh!
Great video as always
This helped me a lot, Thanks !
Super helpful! Thank you :)
Amazing tips!! Thx a lot!
So useful thank you!
Great content :) I ❤ typescript
Wow! Thanks, Josh 🍻🍻
Thanks Josh helps alot for us :D
great video!
Nice one ! Thanks !
Very helpful 🔥
The best thing i have learnt today
Thanks buddy 😊
Josh, would be great if you make a video about the skills a junior developer should have to get their first job. THANKS 4 all your content.
Very greate video thanks
awesome pretty helpful!
About Exlude is mind-blowing! Tnx
This tutorial is valuable
Yep, nice!! Thanks heaps!
This is more complex than learning rust or c or go. Anyway great video :)
That's tips & tricks of Ts is time saving❤
thank you
let God bless you for your kind activity
Do you mean no matter how nested they are or no matter the number of Joins? Great video btw
It is usefull to me thanks!
I wonder will you have a video about a project with bun?
Being mainly a Swift developer I'm left shocked by TypeScript versatility
Prettify is now a vscode extension
Master
I’m a bit confused when writing a function in TS aren’t we meant to declare the return type in the function declaration? When would you need to infer the return type??
This question is kind of backwards. Why would you want to define it? If you can infer it, the types are done. Your code defined them. Manually defining is redundant extra work.
There are cases where you might not want to infer them, but those are the ones you'd need reasons for, which is the opposite of your question.
Let’s assume there is a function that returns an array of some kind of ingredients. In useState you want to declare that you want to keep array of some ingredients, but you start with an empty array. How to type the useState without knowing the return type of that function if you don’t wave the type specified elsewhere? It looks like an edge case but I can see a need for it sometimes
@@DavidWMiller no lol, declaring the return type is beneficial because a reader can see what the function returns without having to interpret the function.
@@gnack420Typescript shows you the inferred type when hovering the function name. No need for reading the code
@@diegofernandocobacruz6508 The IDE does that, not TypeScript. Open it on a notepad and hover it over.
Fuck yea
Nice one ☝️
Our brother always take us from darkness to light .
Thank you Josh 🙏
Great types, you just forgetting `Pick` 👀
3:45 Matt Pockock is a TS Ninja. He has a great channel. So as I understand he contributed to TS and created this type?
I think you can replace all "interface" with "type"
I wonder IS prettify could make typescript faster. Maybe not self implemented but As A buildin type. Because of then could avoid looking up complex structures.
You should have added Pick as well since you showed omit
5:46 Errr... and what will be the return type of updateTodo again? 😝
Looks like somebody forgot another spread operator: ...fieldsToUpdate
type Person = keyof typeof obj
type Return = ReturnType
Partial
Required
type Omitted = Omit
Do u think ai will replace us one day
This is not good. We are adding production code to augment IDE assists. I get why it exists, but this is something that should be supported by TS and the tool chain by default.
thats true
one thing that can be done is "tsc --noEmit --incremental --watch" and that at least shows the errors in the console
prettify is good one
this is good to know, but you don't need any of this besides making things more complex and harder to debug.
The first example doesnt make a lot of sense. Why would you want Person to be either the string literal "name" or "age"
It's just an example probably not the best one. But is super handy when you want to keep track of all keys within an Object or Enum
@@IneyeGabriel I know the feature is useful, but the example makes it more confusing
ReturnType
Awaited
Partial
Required
Omit
Exclude
& {} wtf
Good content, but you need to slow down with the delivery.
I'm an expert at other languages but only just kept up with it.
Aaaaand the prettify type was fake :/
sorry but this is not a high quality content...
sorry but this is not a high quality comment
That Prettify type makes the video high quality
Like every developer finds a bug once in a while 😂
can you please, pretty please, extremely please... not pronounce OUR as or and more like hour? (just phonetically like a-uaer, and not o-ur ... I don't know whay is this so annoying to me... but drives me nuts :)