TypeScript: Why I Will Now Use It For All JavaScript Programming Image

TypeScript: Why I Will Now Use It For All JavaScript Programming

January 15, 2016      .net Programming, Website Design

Why I Have Hated JavaScript

Having started programming in C++ I have always been used to a strongly-typed, object-oriented compiled language. JavaScript has fallen short over the years with no type checking and worst of all, no compilation. Up until a couple of years ago, this was tolerable since JavaScript was used to enhance web pages. But now that it is used as a framework that powers much of the user experience, chasing bugs caused by typos and putting a string where a number should go or some other inane thing can really cost you! Perhaps greater than the hours it takes to find and fix the issues,is the negative impact this has on the users' perception of the application. It's hard enough to gain a user's trust for when writing code that should be helping their business - introduce bugs and that trust becomes exponentially harder to gain.

TypeScript to the Rescue!

Enter TypeScript (www.typescriptlang.org). This wonderful utility finally brings a true compiler to JavaScript. Since I use Microsoft Visual Studio 2015, this is as tightly integrated as the other language compilers. The learning curve is amazingly short since TypeScript make JavaScript seem more like modern C# than decades-old C.

TypeScript works by having definitions of all libraries that are being referenced (much like a C/C++ header or a .net library reference). Once you have the reference in place (most of which are available for free from NuGet) you begin coding with all of the syntax checking and IntelliSense that other languages offer.

While this first step certainly helps eliminate errors, the real beauty is the compiler that converts TypeScript into the actual JavaScript that the browser will read.This compilation step works like any other language and will prevent you from continuing if any errors are found. So at least you know that the only bugs you'll have to chase in your JavaScript are logic-related and not finger-fumbles.

In Conclusion

If you use JavaScript for anything more important than a test project I strongly encourage you to try TypeScript. It is well worth the learning-curve investment as once you know it you will save countless hours of bug chasing. More importantly you will have happier clients!

Share It