Is TypeScript worth it?
I just read Chris Coyier’s You Like It Because You Know It, in which he shares some thoughts about TypeScript and wonders whether it’s worth it.
I’m in a similar position: I’ve been writing TypeScript professionally for over six months, and used it in hobby projects on and off for a year or two. Unlike Chris, I’m definitely on team TypeScript now (but I won’t be obnoxious about it, I promise).
The wrong type of bug
===) and obsessively validate values.
With TypeScript, we still do. It only helps us avoid bugs by forcing us to be explicit about types, or rather type annotations. TypeScript only transpiles code and detects mismatching annotations. It’s a facade, smoke and mirrors, a JSDoc on steroids.
const n = 4.2 as any as string;
Data you can trust
Now that we’ve established TypeScript doesn’t actually do much other than make types visible, let’s explore more indirect effects.
any type with meaningful types, validation and type assertions automatically move towards the boundaries of the application.
Type annotations enable us to be less distrustful about data. It forces us to think about semantics and data structures and lets us write naive code because data types are known. It gives peace of mind.
Is it worth it?
There’s a cost to all this. Although it removes runtime noise, TypeScript does add syntactical noise that can get incredibly complex. Moreover, the error messages can be puzzling, it adds another dependency to the toolchain, and it’s yet another thing people spend time and energy on that could’ve been spent on learning about (web) standards.
It remains fair to ask the question: is it really worth it?
TypeScript eliminates some uncertainty experienced during development. The effects of that are hard to measure. A (potential) increase in time consumed is one, but there are many more: the number of bugs avoided of any type, the impact it has on the overall code quality, and how it affects the mental state of the developer and their productivity.
The unsatisfying answer is: I don’t know if TypeScript is really worth it, and I don’t think there’ll be a definitive answer. I suppose it’s a gamble, a gut feeling, where the outcomes of all choices are ambiguous.
My gut tells me it doesn’t vastly inflate development time or complexity, and it helps me write better code with more confidence. That’s good enough for me.
Was this helpful?🍺 Buy me a beer