Blog

Typescript

Learning Javascript? 5 Reasons to Try Typescript Instead

Typescript

I started teaching myself Typescript about 3 months after I started learning Javascript and it changed the way I developed code. With the more strictly typed Javascript superset, I felt more confident, was able to develop projects faster and with a lot less bugs. Here are a few reason why I believe every new developer should start learning Typescript.

Typescript prevents Simple Mistakes

Every developer makes mistakes whether it be typos, ordering variables wrong in function calls or misusing third party libraries resulting in bugs that take hours to fix. This is especially true when you're learning. This is something Typescript can help a lot with. When using Typescript you get nice friendly reminders if you're using a function incorrectly, you've misspelled variable names or you're expecting the wrong output from a particular function.
Typescript also becomes useful as you start to use more third party libraries. Definitely Typed provides typings for many of the popular npm packages giving you confidence that you're using the library as designed.

You have to learn how to use build tools/compilers

As a new developer, I learned quickly that learning HTML, CSS, & Javascript was just the tip of the iceberg, and that it's rare to find job that's focused only on those three elements. Configuring build systems, learning how and when to use certain compilers is an invaluable skill, often overlooked by those learning web development. When using Typescript it's necessary to compile the code in order to run it in the browser. While this can be as simple as using the command line to compile code, using Typescript makes learning tools such as gulp, webpack more beneficial from the start.

It's self documenting

If you've read third party library code written in Javascript, you've probably come across JSDoc. It serves a great purpose, to document the expected input, and output of the code, give an indication of whether a function/variable is public or private and give a brief description of what a particular function/class does. While Typescript can't completely replace good documentation, strictly typing your functions, allows other developers to confidently use your code knowing exactly what type of inputs they can pass it and what to expect the output to look like. This is especially advantageous in helping more senior developers become more confident in a junior developer's coding ability and allow companies to give more freedom to newer developers.

/**
 * Takes 2 numbers and returns their sum.
 * @param   {number} a the first number
 * @param   {number} b the second number
 *
 * @returns {number} the sum of a and b
 */
function addNumbers(a, b) {
  return a + b;
}

Example of JSDoc from JSDoc Style Guide

Typescript + the right IDE is a dream come true

As Typescript is becoming more widely adopted by companies, the tools we use to write code are becoming smarter, taking advantage of the power Typescript brings to the table. Working with Visual Studio Code and Typescript is a dream. VSCode takes advantage of Typescript to provide auto-complete and type checking ability as you type. Something invaluable to a new developer. On top of that, tools like TSLint can give you even more confidence as it guides you towards maintainining better code styling and syntax.

Typescript Sets You Apart

In a competitive job market, anything you can use to set yourself apart is a huge benefit. Typescript can be just that. As companies start to adopt Typescript into their applications, you can be sure that those job interviews will come a little easier, and your skills will be just that little bit more attractive to a potential employer.

Conclusion

In the end, Typescript is just a superset of Javascript so learning Typescript in no way limits your ability to write Javascript, in fact, I believe it can only make you a stronger Javascript developer.
With that in mind, it should be said that while learning or even mastering Typescript can benefit a new developer in many ways, it is not a replacement for the work that it takes to understand the fundamentals of writing clean, strong code. This is something that can only be learned by continued practice, feedback and hard work. On top of that, learning Typescript despite it's benefits does come with it's own hurdles, ones I believe will make somebody a better developer, but that can often times frustrate new developers.