Speaking of programmers, one of the stated goals behind TypeScript was to help programmers familiar with strictly-typed languages (such as Java or C#) transition to web development. One of the major advantages of TypeScript is its similarity to those established languages.
Not just a language
One of the biggest advantages of TypeScript is the fact that it’s not just a language: it comes with a very mature tooling ecosystem, which includes a compiler and integrations for the most popular IDEs and text editors.
The strong typing present in TypeScript allows for the use of highly-productive tools and practices in modern software development. Refactoring your entire project becomes a breeze, while static type checking ensures the high quality of code.
Oh, and if you were wondering if TypeScript plays well with Angular and/or React, rest assured – Angular pretty much requires the language, while the TypeScript + React combination is steadily gaining in popularity.
Why Typescript, then?
Strong typing enforces good coding practices
Let’s consider an all-too-common scenario. Imagine you’re a programmer, newly assigned to a project. Your first assignment is to properly format the output of a function which takes a single argument, foo. Sounds simple enough, right? But what even is foo? Is it a string? Is it a number? Is it an object?
Unfortunately, the previous coder on the project didn’t properly comment his code. After all, if he could figure out what foo was, why can’t you?
And so, you set about digging through the rest of the codebase, looking for every place where the function was called to figure out what foo is meant to be. And just like that, a ten-minute job turned into an hour-long investigation, because reading the code turned up more uncertainties and the previous programmer was last seen hurriedly buying a one-way ticket to Timbuktu.
If only there was a type attached to the foo variable – at best, the most work you would have to do was look up the class definition.
To the more experienced amongst you, this example may seem trivial – and that’s exactly the point. After all, trivial mistakes are the easiest ones to make.
Easy to maintain codebases
If you apply our previous example to a large app project – large projects being explicitly what TypeScript was designed for – and we can immediately see the benefits. Because of the way static typing subtly encourages programmers to work in a very specific fashion. From a business standpoint, this manifests itself in two primary ways.
Firstly, programmers working in statically-typed languages are subtly encouraged to follow certain patterns when writing code. Chief among these patterns is the separation between definitions and actual logic. Like our previous example demonstrates, it’s useful for onboarding new project members – but it also makes refactoring a breeze. It’s much, much easier to implement major changes when you know where everything is supposed to go. As an added bonus, code written that way is much easier to read for humans – making code reviews fun.
Because TypeScript apps have to compile, the most common bugs can be caught at that time – saving you precious man-hours which would otherwise be spent on fixing bugs well after they were introduced into the codebase.
It’s all optional!
What this means in practice is that you don’t need to re-write your entire codebase just to take advantage of a single feature. Your development team can explore TypeScript at their own pace, learning as they build new features. In fact, this is also one of our favourite React features – why not kill two birds with one stone and try two exciting new technologies at the same time?
Well, what’ll it be?
Who knows – maybe it’s exactly what you’ve been looking for to make your web development experience that much more pleasant.
If you feel like you wanna talk about using Typescript in your project – let us know on email@example.com !