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 Full Stack Software Engineer specializing in low-code development, with a strong focus on building secure, scalable applications using Quickbase and cloud-integrated automation platforms.
My name is Ikechukwu Charles. I am a Front-end web developer. I really love honing my skills to the extent that I started writing my own Javascript UI library from scratch, and playing basketball.
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
as
like 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
Record
e.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.
Really nice list!! Thank you!!
Very helpful tips.
Nice collections, thanks for listing all these...
Great
Thanks, this was very helpful.
Nice
Thank you for the great explanation. It helped me review the topic.
The
as const
thing is also not really correct. If you don't want to be able to mutate properties you should usereadonly
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.
Сongratulations 🥳! Your article hit the top posts for the week - dev.to/fruntend/top-10-posts-for-f...
Keep it up 👍
I think the second one is more about mapped value?
Enum is considered bad practice.
It's more flexible to use a const: