In this article, I’ll explain why TypeScript should replace JavaScript in your tech stack. I’ll address the major excuses people bring up when this topic arises. By the end of it, if I’ve done my job right, you’ll use TypeScript for your next project.
Why People Avoid TypeScript
Seems overkill for personal projects.
This is one of the many reasons folks avoid TypeScript. When you’re used to writing everything in a dynamic language like JavaScript, it feels tedious.
Or maybe you’re experienced enough that you already know how to avoid common JS pitfalls. You don’t get the “aha” of types.
Let me start by telling you, “I get it.” I was there too. It wasn’t until my friend @TejasKumar_ helped me migrate one of my JS projects to TS that I finally understood the hype around static types. It gave me a whole new level of confidence in my programming.
My goal for today is to talk through some of my favorite aspects of TypeScript and convince you to try it for your next project.
Show me the code
If you want to see a basic example in TypeScript, take a look at this TypeScript Playground link.
Why I Love TypeScript
Now that I’ve used TypeScript in my default stack for the past 4 years, I know exactly what I love about it.
I feel more confident
JavaScript is my jam but I’ve shipped runtime bugs that cause the white screen of death in production. Using TypeScript correctly, I know that I can eliminate that entire class of bugs.
The type safety gives me a certain level of confidence that was lacking in JavaScript. I no longer have to write meaningless unit tests that check, “what happens if I pass a number instead of a string to this function?” Nope. That time is now spent building fun features and shipping real value to users.
I’m more productive
When my IDE understands what types I’m working with, it gives me autocomplete and it’s beautiful. Remember in school when your English teacher would mark up your paper with red ink?
TypeScript does exactly that inside your IDE. It yells at you when you pass in the wrong type. And most of the time, it tells you how to fix it! That means you fix issues while you’re developing rather than after pushing to prod. I can’t tell you how much time it’s saved me. Faster feedback loop means less time crushing bugs and more time shipping features. Now that’s efficiency for you.
My code is self-documenting
This is probably the top feature for me in TypeScript. My code documents itself. You can look at it and know exactly what it wants and what it returns thanks to static types. I find myself writing fewer comments over the years because most of it is self-explanatory.
Most IDEs will show you this information on hover or you can “Jump to definition” and see where the types are defined. This means it’s 10x easier to debug third-party libraries written in TypeScript as well. Boom boom. Win-win for you and the future you forgetting all the code you wrote last month.
Resources
For experienced JavaScript developers who want to get started with TypeScript, take a look at the following resources:
- TypeScript Course: free 3-module email course
- Total TypeScript: free video tutorials with coding challenges
- TypeScript for JavaScript Developers
- TypeScript videos on egghead
Summary
Today I shared my favorite parts about TypeScript with you in hopes that it becomes part of your default toolkit. For me, it’s helped me write safer, more maintainable code faster than before. I use TypeScript both at work and for personal projects and can’t imagine going back to JS.
But don’t let this article convince you - set a timer for 5 mins and try it yourself. It’s best to experience it first-hand.
Last thing, I'll be holding "TypeScript Office Hours" where you can:
- vent
- get advice
- do code-reviews
- teach me something
- get project feedback
- talk about imposter syndrome
- learn about contributing to open source
Sign up here 👉🏼 https://savvycal.com/typescript-course/chat