Tips
Explore important TypeScript tips to enhance your React projects. Learn how to use strict mode, leverage type inference, avoid the any type, work with readonly properties, and apply unioned string literals to improve code safety and readability.
Hover to discover the type of native browser elements and functions
TypeScript types do exist for native browser elements like span, div, and input. Types already exist for native browser functions like fetch as well. But what are the types of these elements and functions? Well, if we are using Visual Studio Code, then we can hover over where the item is referenced, and a tooltip will show us the type information!
Use strict mode
We’ll get the most benefit out of TypeScript if strict mode is on. It is particularly useful in helping us avoid the any type and null reference problems. ...