TypeScript is supposed to make your development life easier, but I vividly recall my earliest memories of TypeScript involving a lot of cursing, confusion about errors, and wondering why anyone would ever waste time writing out all types. I used to write type definitions for hours and complain that I definitely didn't feel my productivity getting any better. Today, I love TypeScript and usually find projects written in plain old JavaScript to be injurious to my mental health.

10m read timeFrom dev.to
Post cover image
Table of contents
1. Use Ctrl + Space to see all the available props of a component, or all the available keys of an object.2. Use as when you know the type of your variable better than your linter.3. Use Pick and Omit to efficiently create typed sub-components4. Cmd + click on things to explore what they expect.5. If you have a list of options, try writing your own type instead of using a generic string or number type6. Auto-import all missing variables with Cmd + .7. Get optional props the smart way using a ? operator ("Optional chaining")8. Work with old JS files by enabling allowJs in tsconfig.json9. Automatically refactor your typed objects into a named interface10. Combine TypeScript with JSDoc for awesome documentation right in your VS Code.

Sort: