TypeScripting Away

One thing I have disliked about JavaScript is it feels lacking when I program in it. It is very powerful, but I miss strongly typed variables, and decent code completion for custom data structures. Then during Build 2015, I got to watch a presentation about TypeScript.

What is TypeScript

Well...according to their website:

TypeScript lets you write JavaScript the way you really want to. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. Any browser. Any host. Any OS. Open Source.

I though to myself "This is cool. This is very cool." More and more have I been developing JavaScript applications, especially for dynamic web content and I can see immediately how TypeScript can help speed up in both development and testing. Thanks to the DefinitelyTyped Repo, it is a great help when doing NodeJS development.

Using TypeScript had only been a small project at home until a friend, Chris, had to get a presentation ready for work. I volunteered to help make a small customer tracking app for part of his talk. Using TypeScript made implementing the data model much more easy and made it simple to track everything as development progress. As the little project came to an end, TypeScript has shown it strengths and a few weaknesses.

Benefits of TypeScript

Making a fully interactive app utilizing TypeScript and Angular was super easy. It took some difficulty getting everything setup at the beginning. We were utilizing both IntelliJ and Visual Studio for development. Getting both to use the same TypeScript compiler version wasn't the easiest as finding out what version each used was not as straight forward as it could of been. The fact that we were able to use two different build environments was great. TypeScript only requires NodeJS to compile into JavaScript, which runs pretty standard across most environments now.

TypeScript really pushes the ideas of modules for name spacing and enforcing data types on variables. When you get into a large JavaScript application, it can become very hard to track down what time of variable you are dealing with and where it can be used. While the compiled JavaScript can still be a pain to view, and many of the rules of TypeScript can be broken in it, while developing with the TypeScript code, it helps give you the same error reporting you expect from any modern language.

Cautions to watch

One thing that you need to keep in mind in a application build in TypeScript as you do with all JavaScript applications, your code goes to the user directly. This mean, like normal, make sure all the data you send back needs to be double checked. Considering many browsers offer editors directly for the code, relying on the client side to keep data confidential could get you into trouble. There are likely solutions out there already for this, but it is a good idea to keep it in mind during development.

Future Development

The more the I use TypeScript the more I like it. There are still some of the oddities that you expect from JavaScript in it, but that will likely not change. As a tool to develop some amazing web applications, TypeScript will always be in my toolkit, and you should likely make it part of yours. I'll likely do more talking about it in the future, and if there is a demand, about setting up NodeJS and TypeScript to make some cool applications.