Microsoft Announces TypeScript: Will It Change The Web?

Like it or not, JavaScript has long established itself as a de-facto scripting language on the web. There are many programmers who are in love with JavaScript, and then there is an equal number of programmers who hate it. Yet, if you are developing for the web, you most probably deal with JavaScript in some way or another, at some point or the other.

Owing to such popularity, JavaScript has seen its fair share of clones copies languages that attempt to replace or build upon JS. CoffeeScript is a shining example, for instance.

Among such examples, we recently saw a new entrant few days ago. Yes, Microsoft announced the release of TypeScript, a typed superset of JavaScript.

What is it all about? Read on as we take a look at it in this article!

TypeScript: An Introduction

So, what exactly is TypeScript? As it becomes clear, TypeScript is a language for application-level JavaScript development. It is based on JavaScript, complies to JavaScript, but is better than JavaScript (or at least that’s what folks at Microsoft want us to believe).

Basically, in its purest form, JavaScript lacks certain features that are otherwise common: for example, in-built module system and static type checking aren’t present in JavaScript. TypeScript wishes to build upon these very areas.

Certain noteworthy features include:

  1. Class declarations
  2. Support for modules
  3. Optional static typing
  4. Visual Studio plugin

The language is scalable and open source and comes with an Apache 2.0 license. Another shocking point, isn’t it? Microsoft hasn’t been known for its open source ventures ever. In fact, its products such as Windows and IE often receive the maximum amount of hatred from the open source community.

TypeScript: The Reasons

Why exactly did Microsoft feel the need for launching TypeScript? This is one question that only MS can answer. We shall, however, try our best to figure it out.

Google already had come up with its own answer to the problems related to JavaScript in the form of Google Dart. Couldn’t MS simply back Dart and support it, rather than wasting its time and energy on a new language? Probably not. Firstly, MS will not bother backing its rival Google’s creation. Secondly, Dart is known for exhibiting a radical departure from JavaScript (to the extent that many feel Dart aims to replace JavaScript altogether). Naturally, if Microsoft were to address the JavaScript user base, going with Dart wouldn’t have helped.

However, one wonders, if Dart was not serving the purpose, why wasn’t CoffeeScript considered? Also, on a related note, did JavaScript really need stuff such as static typing?

However, business and opinion questions apart, Microsoft does indeed have a practical interest in JavaScript. First up, both Bing Maps and MS Office Web Apps have something or the other to do with JavaScript, and the development teams for both these products have had their share of confusion with it. In fact, it is this very practical need — the upcoming projects’ reliance on JavaScript — that led to Microsoft’s interests in TypeScript development.

Furthermore, with the desktop OS being replaced by the internet OS (read: Windows no longer a dominant monopoly), Microsoft at least wishes to present Visual Studio as a legit entity, and offering an open source TypeScript with some added awesomeness is both a smart and noble (clever?) move.

TypeScript: The Details

Basically, TypeScript is a super set of JavaScript: you can write JS code within TS, and no one will declare you guilty. That said, as mentioned above, TypeScript offers additional goodness and features that are otherwise lacking in JavaScript. Unlike Dart, TypeScript does not provide you with new syntax rules: it accepts all that is good in JavaScript, and offers certain newer additions of its own.

For the sake of simplicity, we shall take a look at the simple case of type inference in TypeaScript. If you declare something like this:

var c = 100;
var me = “awesome”;

TypeScript will automatically infer that the former variable holds a numerical value, whereas the latter is a string type.

TypeScript also supports classes with the optional type annotations integration:


class Person {
private name: string;
private age: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
toString(): string {
return this.name + " (" + this.age + ")";
}
}

Code Courtesy: Wikimedia Commons

The language comes with support for features proposed in the upcoming ECMAScript 6 standards.

Wish to learn more about TypeScript? You can master it using the specifications’ file here.

Note: Above link directs to downloadable DOC file.

Conclusion

So, is TypeScript worth it? In a scenario in which the internet is, to a good extent, powered by JavaScript, Microsoft has tried to augment JS and its features and couple them with a creation of its own in the form of TypeScript. The plan in itself is good, and though it has so far received a mixed reaction, it is pre-mature to declare it a success or failure straight away. I’m happy that the language is open source, and unlike others, it is not refusing to acknowledge that it comes from JavaScript.

What do you think of TypeScript? Will you be using it? Share your thoughts with us in the comments!

Related Links

Sufyan bin Uzayr

Sufyan bin Uzayr writes for various magazine and blogs, and is the author of "Sufism: A Brief History". He blogs about technology, Linux and open source, mobile, web design and development, typography, and Content Management Systems at Code Carbon. You can learn more about him, follow him on Twitter or friend him on Facebook and Google+.

15 Smart Tools To Help You Build Your Freelance Business

Discover the awesome tools we use in making our clients comfortable and happy in learning new things every day.

Download Now

Comments

  1. Bless Quarshie says

    Changing the web? Not very likely.
    MS with respect to web standards are being very lax. IE is still a pain in the neck to work with, talking about standards-compliance (in spite of version 9), and well, they may have put some innovation into TypeScript – maybe things that JS should have had by now – classes for one – so perhaps there is a little innovation there.
    But for me, that’s just about it. I really don’t think TypeScript will be making too much waves. That it’s available as a plugin for Visual Studio is also an interesting thought; that might be what fuels the widespread use of it. Open source? Hm, MS what are you up to?

  2. John says

    Did you know that JavaScript++ and JSX, which also extend JavaScript, existed long before TypeScript? So why is MS reinventing the wheel?
    But if you decide to use TypeScript, you can simply include it in a HTML page, just as JavaScript, thank to TypeScript Compile: http://bit.ly/RKCykc

  3. says

    Microsoft continues to surprise me in out detached a major corporation can become from their market. They continue to put tons of money into IE 9 while not supporting simple new CSS3 features. ASP was more of less a rip-off of PHP, and this is just an attempt to compete against something they really don’t need to be competing with. It reminds me of how Apple recently detached themselves from Google maps since Google was a competitor – Google will never be like Apple, why fight over these little things. If competitors let each other take their niches and simply compete at what they’re good at this nonsense might not be occurring. This is all the business side of me talking though, I may be missing something here possibly.

    • says

      “just an attempt to compete against something they really don’t need to be competing with.”
      –Yes, if they are trying to compete against JS, I agree with you 100%. However, if MS is indeed keen on using static typing and class modules along with JS, then TypeScript might not be a bad innovation after all.
      Time will tell us about their real motive: business competition or mere improvisation. :)

  4. says

    Excellent write up. I for one plan to learn TypeScript soon. It’s nice to see the power of Visual Studio finally being used in conjunction with JavaScript.

    • says

      Hey! Yes indeed, I’m also looking forward to the impact TypeScript has, and I’ve already started experimenting with it. With the added goodies like static typing, it seems more “my kinda” language now, as compared to JS. :)