View profile

Is TypeScript Worth It?

Is TypeScript Worth It?
By Mastering JS Weekly • Issue #53 • View online
TypeScript is growing rapidly: it is now the 7th most popular language on GitHub, recently overtaking PHP. TypeScript is “JavaScript that scales”, which is an excellent marketing tagline. That’s an opportunity to work on a critical developer skill: thinking critically about marketing taglines. There’s always more nuance to a technical subject than you can fit in a pithy slogan.

TypeScript's got what JS developers crave
TypeScript's got what JS developers crave
Static vs Runtime Typing
TypeScript is all about static typing. In other words, TypeScript can help guarantee your code is internally consistent in terms of passing the right values to function signatures, but it is limited in the sense that it doesn’t necessarily check the input to your system. For example, below is a TypeScript Express server.
TypeScript can't guarantee the type of `req.body`
TypeScript can't guarantee the type of `req.body`
If you send a JSON body `{“a”:1}` to the above server using Postman or a similar HTTP client, the server will crash. The reason is simple: `req.body` can be anything at runtime because you can send any data you want in the HTTP request body.
This limitation is not news to experienced TypeScript developers. But it does provide some insight into where TypeScript provides value.
When is TypeScript Worth Using?
TypeScript does have some serious advantages when you have a large team working on a single codebase. Vue is a great example of a project that benefits from TypeScript: numerous core contributors, lots of outside contributors.
However, the reason why TypeScript works well for Vue is that Vue is a single project where the primary interface between Person A’s code and Person B’s code is a function signature. TypeScript can check the function signature and find cases where changes are incompatible.
On the other hand, suppose you’re an individual contributor building a Node.js microservice that primarily consumes data generated in a different programming language. This is an example where TypeScript doesn’t provide much value: the primary interface between your code and other people’s code is a network call where TypeScript can’t ensure compatibility between caller and callee.
How valuable TypeScript is depends on how your code primarily interfaces with other people’s code. If via function calls, then TypeScript is more valuable. If via network requests, then less valuable.
Mastering JS is sponsored by Vue School, check out their Vue courses!
Mastering JS is sponsored by Vue School, check out their Vue courses!
Most Recent Tutorials
JavaScript Enums - Mastering JS
Other Interesting Reads
Static Typing is Dead: Runtime Type Casting with Archetype | www.thecodebarbarian.com
Practical Aspect Oriented Programming in JavaScript | www.thecodebarbarian.com
Did you enjoy this issue?
Mastering JS Weekly

A weekly summary of our tutorials

If you don't want these updates anymore, please unsubscribe here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Powered by Revue