1.Optional Chaining (?.):
Optional chaining allows you to safely access nested properties or methods without worrying about null or undefined value...
For further actions, you may consider blocking this person and/or reporting abuse
Hey bro, great post!!
A small observation. For point 8 you can use the
Partial
Type like this:Even, add new properties, for example:
__
Another one I enjoy quiet often is the const assertion. With them you can make stuff readonly outside of class members. For example:
With as const:
Without as const:
Hey 👋 Nice post 😉
An improvement for point 3 :
Most of the time, when we create something with
unknown
it's because you don't know how to provide. In your case, you specify a string value that could be confusing for some beginner developers.What do you think ? 🙂
You should avoid type assertion as much as possible. You're basically telling typescript to ignore itself and listen to you instead.
Instead of type assertion, use typeguards. You can even make a function to narrow down the type:
Сongratulations 🥳! Your article hit the top posts for the week - dev.to/fruntend/top-10-posts-for-f...
Keep it up 👍
in the optional chaining
const invalidCode = user.address?.postalCode?.toLowerCase();
console.log(invalidCode); // Output: undefined
not log undefined
Nice list 👍 One thing I would add to the type guards example is the
is
operator: typescriptlang.org/docs/handbook/a...Great post! I've never looked a lot into decorators until now, would've never thought they were so straightforward to implement
It's true no matter how experienced you are, you indeed need some good tools to make you shine. Thanks for writing such a great article.
A useful list, and very well presented -- even if the first two are native Javascript features, not specific to TS :)
Congratulations. It’s a great post and I believe it will help a lot of beginners!
Hi bro, great post!
I wonder if you can take these rules and lint your code with ChatGPT...