Hey everyone, I'm working on a project using HTML, CSS, and JavaScript, and I've been trying to make my code neater through refactoring. During this process, I encountered some bugs, particularly when renaming variables like `inputRight` to `rightInput`, and JavaScript didn't alert me about `this.inputRight` being undefined. It led to some unexpected behavior that was hard to track down. I attempted to use "use strict" and ESLint, but they didn't help much with identifying the issue. Then, I renamed my file from `.js` to `.ts`, and suddenly TypeScript caught the error without any code changes! This got me thinking: if TypeScript can catch errors more effectively, why do some developers still prefer to use plain JavaScript? Am I missing something important? Would love to hear what you all think!
5 Answers
Some folks just prefer the raw JavaScript experience. They’re confident in their ability to debug and test, so they don’t want extra tools getting in the way of fast coding. Type checking is handy, but for quick scripts or if you’re comfortable, plain JS can be just fine too!
You’ve touched on a key point! If you can easily switch from JS to TS, it means you’re likely using a build tool that supports it. Many serious projects today rely on these systems, making TypeScript a common choice. Type safety is super crucial for large applications, so I’d definitely recommend it!
True, I use Vite for my projects!
Actually, you can use TS without a build step! Just set up a tsconfig with `allowJS` and `checkJS`, or add `// @ts-check` at the top of your JS files.
One alternative to TypeScript is using JavaScript with JSDoc. This allows you to get some type checking in your editor without the hassle of a build step. It’s definitely worth exploring both options to see which fits your needs better. However, for many projects, TypeScript really holds the edge if a build step isn’t an issue.
I’ll look into JSDoc, thanks for the tip!
I prefer sticking with plain JS since modern IDEs offer type hinting without the extra build complications. I do use TypeScript for specific projects, but I find JSDoc in standard JS more user-friendly. It’s straightforward without the convoluted type walls, plus you can generate TS types if needed.
But why go for a full IDE if you don’t need a build?
Honestly, the last 7 years, the only times I’ve touched JS was to refactor it into TypeScript. I can’t imagine not using TS by 2025; it’s just too beneficial! Your scenario highlights why TS is becoming essential, especially in larger codebases. Imagine missing type errors in a massive script—yikes!
I’ve worked on large projects without TS and managed fine. It’s all about knowing your code and testing well.
Or maybe they just don’t care about types and prefer keeping it simple.