Kay, how do I know when to use TypeScript
When and when not to use TSX
What the hell is even typescript?
Here are a few one-liners that I could come up or find that do a good job of explaining typescript in one sentence:
- “Typescript is JavaScript for people who hate JavaScript”
- “Typescript is just JavaScript, but with extra syntax (like java, c, or c++)”
- “Typescript is a superset of JavaScript which strengthens JavaScript by sitting on top of it and adding an extra build step”
- “Typescript is just JavaScript with types.”
When should you not use it?
See since Typescript is just JavaScript, but with extra syntax, it’s gonna occupy more lines of code, and it’s by default gonna take you more time in building because you’re kind of installing those safety checks for the future. So here are some use cases when you should steer away from it:
- If you want rapid prototyping and wanna get your MVP in the market FAST or are under a time constraint or a tight deadline, this may cause unnecessary delay. Use JavaScript in that case.
- If it’s a small project, the complexity + configuration + additional build steps = not good for small projects. So for small apps sure, use untyped code.
- If it’s one guy or a very small team project, you can use JavaScript.
- If you want less configuration, fewer false errors, faster builds, fewer compatibility issues when using 3rd-party stuff, and smaller payloads use JavaScript.
When should you use it?
- Typescript = fewer bugs and runtime errors.
- Large project = Use Typescript.
- Team size > 3 people = Use Typescript.
- If you don’t wanna end up writing documentation for your JavaScript, use Typescript. It also gives the code more structure, makes it self-documenting, and more readable, and speeds up debugging and refactoring.
- For apps that must be consistent through time and different team members, untyped code is your worst enemy, use Typescript.
- In the long run, it will save us a lot of time because a new developer will need a lot less time to understand the codebase.
My Unsolicited Opinion.
In 90% of cases, I’d recommend don’t waste time choosing this language or that language. Just pick one and stick to it. What matters more is getting the product out in the market fast and getting that juicy user feedback about your product and iterating upon it quickly.
If you’re a developer reading this and thinking if you should learn it or not, then I’d say:
“If the only tool you have is a hammer, all problems will look like nails”
And it’s always nice to have more tools in your toolbox. You never know which one might come handy to satisfy your customers.