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:
in the optional chaining
const invalidCode = user.address?.postalCode?.toLowerCase();
console.log(invalidCode); // Output: undefined
not log undefined
Unlock the full potential of TypeScript with these Advanced Tips for Development! 🚀 Master conditional and mapped types for precise logic, wield template literals for flexible string manipulations, and harness polymorphic types for fluent API chaining. Elevate your coding game with distributive conditional types for seamless union handling. Dive deep into these advanced techniques, and propel your projects to new heights of scalability, maintainability, and efficiency. Stay ahead in the dynamic world of web development! #TypeScriptTips #WebDevelopment
Сongratulations 🥳! Your article hit the top posts for the week - dev.to/fruntend/top-10-posts-for-f...
Keep it up 👍
Nice list 👍 One thing I would add to the type guards example is the
is
operator: typescriptlang.org/docs/handbook/a...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.
Great post! I've never looked a lot into decorators until now, would've never thought they were so straightforward to implement
A useful list, and very well presented -- even if the first two are native Javascript features, not specific to TS :)
Hi bro, great post!
Congratulations. It’s a great post and I believe it will help a lot of beginners!
I wonder if you can take these rules and lint your code with ChatGPT...