I'm a coder who has worn a lot of hats, from individual contributor to lead engineer to "CTO" (yes, in quotes, make of that what you will!). I've plenty to learn and hopefully some to share as well.
Nice tips. In my opinion the main thing that separates pros from newbies is that pros turn on all the strict options and still manage to avoid as like the plague because they know a ton of tools like these to avoid it. Death to as!
Great tips! I'd like to contribute one more suggestion. Instead of using "any" for typing inputs in your type guard, it's safer to use "unknown". This approach encourages you to first check if a parameter is of type object before accessing its properties. You can see this here: youtube.com/watch?v=p-YEN-9KnRo
I am a software engineer building LLM-powered applications and data pipelines. My core stack is Python, TypeScript, React and SQL on AWS, shipped through Git and GitHub Actions CI/CD.
Thank you for these tips. Especially the Partial, Pick, Omit & Required Types help me, as I only knew Partial<>, but I have a usecase for the other ones too.
The as const thing is also not really correct. If you don't want to be able to mutate properties you should use readonly before each property. as const is used to produce compile-time constants, for example to allow you to map names to string literals at compile time.
Great article and excellent tips.
Some of them are very useful.
I've created a repo to test out the above tips & tricks on my local machine. It is public if anyone wants to clone the repo and tests the tricks that Tapajyoti Bose shared with us. github.com/Yiannistaos/learning-ty...
These are wonderful for design time. But you should make it clear that this opens you for lots of runtime problems, and am those check need to them be fine elsewhere. All of these types are removed when the code is 'compiled'.
So many bugs introduced into codebases because this loss of type information at runtime is not understood.
All those checks you mentioned still need to be done somewhere, but not everywhere.
Nice tips. In my opinion the main thing that separates pros from newbies is that pros turn on all the strict options and still manage to avoid
aslike the plague because they know a ton of tools like these to avoid it. Death toas!It's now generally recommended to write index signatures using
Recorde.g.type ParticipantData = Record<string, ParticipantStatus>.Great tips! I'd like to contribute one more suggestion. Instead of using "any" for typing inputs in your type guard, it's safer to use "unknown". This approach encourages you to first check if a parameter is of type object before accessing its properties. You can see this here: youtube.com/watch?v=p-YEN-9KnRo
This is a nice summary of TypeScript tricks. Thank you for putting it together.
Using TypeScript has changed my approach to programming for the Web. And I'm grateful to have access to this technology.
I was looking for this type of article. Where I can learn all about props types. Thanks for sharing
Hello. Do you mean React prop types? What prop types exactly?
Very good article and examples! :)
Thank you for these tips. Especially the Partial, Pick, Omit & Required Types help me, as I only knew
Partial<>, but I have a usecase for the other ones too.Thanks, this was very helpful.
Very helpful tips.
Nice collections, thanks for listing all these...
Thanks, this was very helpful.
Really nice list!! Thank you!!
Great
Thank you for the great explanation. It helped me review the topic.
Nice
The
as constthing is also not really correct. If you don't want to be able to mutate properties you should usereadonlybefore each property.as constis used to produce compile-time constants, for example to allow you to map names to string literals at compile time.Great article and excellent tips.
Some of them are very useful.
I've created a repo to test out the above tips & tricks on my local machine. It is public if anyone wants to clone the repo and tests the tricks that Tapajyoti Bose shared with us.
github.com/Yiannistaos/learning-ty...
These are wonderful for design time. But you should make it clear that this opens you for lots of runtime problems, and am those check need to them be fine elsewhere. All of these types are removed when the code is 'compiled'.
So many bugs introduced into codebases because this loss of type information at runtime is not understood.
All those checks you mentioned still need to be done somewhere, but not everywhere.
I think the second one is more about mapped value?
Π‘ongratulations π₯³! Your article hit the top posts for the week - dev.to/fruntend/top-10-posts-for-f...
Keep it up π
Enum is considered bad practice.
It's more flexible to use a const: