Offline

TypeScript: Enhanced Javascript

One of the most important platforms nowadays is the web, and Javascript incorporates a large share from any web application today more than ever. As we get more into the single page applications trend and Javascript on the server (such as NodeJS), this language can't be really dealt with as secondary anymore. In fact it isn't just about the web, Javascript is extensively used in cross mobile app frameworks and also making its way into the desktop, it is everywhere. Yet, there is a large number of developers, enjoying languages like C#, who don't like working with Javascript for reasons such not being a strongly typed language, and not having class structures.

This is where TypeScript kicks in.

How can TypeScript help?

TypeScript isn't a language designed to replace javascript, it's a typed superset of it. This means that JavaScript code would be valid TypeScript, and what the compiler generates is JavaScript. The language was designed with the .net developers in mind and that's why it packs many cool features you may already be using in your favorite .net language such as C#. In reality all "features" can be achieved in Javascript by following certain patterns. Yet an advantage other than having syntactic sugar for Javascript is that you get rid from all the boilerplate Javascript code you end up writing to achieve those patterns. MSDN have published a very nice article showing off some of TypeScript's features along with comparison against classic Javascript code. The result is concise code that is enjoyable to read and maintain. I highly recommend checking the examples out.

What about Coffee Script and Dart?

Since the release of TypeScript there have been a lot of comparison with Coffee Script and Dart. They're both different than each other and TypeScript. In both of those languages you're not writing any Javascript, they have their own languages that get compiled to Javascript code. On the other hand, TypeScript is a superset of Javascript where you write it just like you write Javascript, and any Javascript code is already valid TypeScript. A superset language is one that contains all the features of a given language and has been expanded or enhanced to include other features as well.

What's ahead?

In my opinion Typescript represents what Javascript is supposed to be, or will become like one day. Afterall, ECMAScript is progressing and some of the features supported in TypeScript will probably be available in ECMAScript 6 such as classes, modules, and arrow functions. As we head to a future dominated by Javascript, the language will keep moving on with new features. Alternatives to writing Javascript like Coffee Script are already getting popular, while some good features available in TypeScript are being weaved into ECMAScript 6. Where do you and your work stand from all what's going on? Would love to hear your opinion.

Enjoyed this post? Help me spread the word and let me know your feedback!

Subscribe via