Could TypeScript be the future of JavaScript?

Will Microsoft's TypeScript succeed where so many others have failed?

JavaScript, it's no longer the avoidable nuisance it once was. The flexibility of of the language and its ubiquity on the client side have brought it front and center for modern web developers. The creation of popular JavaScript frameworks, such as jQuery, MooTools, YUI, Dojo, and GWT to name a few, have eased much of the pain when it comes to coding, but most of the shortcomings of the language are still inherent.


For developers used to object-oriented programming, the lack of classes in Javascript along with a lack of static typing and lack of compile time errors generally translates into buggy JavaScript code and a pile of difficult to maintain .js files. Several attempts have been made to circumvent these deficiencies and improve upon the language, each with varying degrees of success. Arguably the most popular attempt is CoffeeScript, a programming language inspired by Ruby that trans-compiles into JavaScript. Google is even trying to replace JavaScript entirely with its own object-oriented based language, Dart. The uphill battle that they both face is that they each have a new syntax quite different from JavaScript that increases the barrier to entry.

Introducing TypeScript

One of the more recent and notable entries to the JavaScript improvement game is Microsoft's TypeScript. TypeScript is a superset of Javascript. The language starts from and results in JavaScript code. The syntax is the same, it simply adds development time features to help produce easier to manage and easier to debug code that compiles down into plain JavaScript. This is similar to how CoffeeScript works but with the major distinction that the syntax with TypeScript is familiar to far more developers.

The main additions to JavaScript that TypeScript provides are:

  • Optional static typing

  • Classes and Inheritance

  • Interfaces

  • Modules

  • Lambda Expressions

Since these features ultimately compile down to JavaScript they are nothing more than syntactic sugar, but by combining their convenience, readability, and maintainability with the advanced tools in Visual Studio 2012, developers are given a platform on which to build large applications. With TypeScript and Visual Studio 2012, developers will get features that JavaScript programmers long for. Features like code navigation, code refactoring, Intellisense, find references, renaming, and static error messaging. Add to that the fact that existing JavaScript code, which is already TypeScript code, can be brought directly into TypeScript with no modification. This gives you an extremely reduced barrier to entry, especially for shops already running Visual Studio.

It seems like shiny new tools pop up every day around JavaScript, but this one in particular is appealing to me in a way that only jQuery and Twitter Bootstrap have been thus far. Bootstrap doesn't replace jQuery, it compliments it very well. Likewise, TypeScript doesn't replace jQuery or Bootstrap, it enhances them and allows you to build larger applications in a more reliable way.

It seems like the future.

Scott Hanselman says in his post about TypeScript:

From what I can see after using TypeScript for a few days is this. It gives you type checking, explicit interfaces and easier module exports. In fact, it's a little like getting some of tomorrow's ECMAScript 6 early in a way that's compatible with today's JavaScript. ES6 won't be out for at least a year but we can play with some of those features today.

If you write JavaScript heavy software you owe it to yourself to check out TypeScript. Have a look at the Channel 9 introduction video below or take it for a spin at the TypeScript Playground. It is of course too early to see if TypeScript will succeed where so many others have failed, but in the short term it appears to have all the right moves to gain some ground in a fragmented market.

Channel 9 TypeScript introduction video

This story, "Could TypeScript be the future of JavaScript?" was originally published by ITworld.

Copyright © 2012 IDG Communications, Inc.

7 inconvenient truths about the hybrid work trend
Shop Tech Products at Amazon