Please create an account to participate in the Slashdot moderation system


Forgot your password?
Programming News

TypeScript: Microsoft's Replacement For JavaScript 488

mikejuk writes "Everyone seems to have a replacement for JavaScript — Google even has two. Now Microsoft has revealed that Anders Hejlsberg, the father of C# among other languages, has been working on a replacement and it has released a preview of TypeScript. The good news is that it is compatible with JavaScript — you can simply load JavaScript code and run it. JavaScript programs are TypeScript programs. To improve on JavaScript, TypeScript lets you include annotations that allow the compiler to understand what objects and functions support. The annotations are removed by the compiler, making it a zero overhead facility. It also adds a full class construct to make it more like traditional object oriented languages. Not every JavaScript programmer will be pleased about the shift in emphasis, but the way it compiles to a JavaScript constructor is fairly transparent. At this early stage it is difficult to see the development as good. It isn't particularly good for JavaScript developers who already have alternatives, and it isn't good for C# developers who now have confirmation that Ander Hejlsberg is looking elsewhere for his future." Update: 10/01 20:34 GMT by U L : It's also freely available under under the Apache 2.0 license, and there's a language specification available. It looks pretty interesting: it even has ML-style type inference (including e.g. deducing the types of higher order functions).
This discussion has been archived. No new comments can be posted.

TypeScript: Microsoft's Replacement For JavaScript

Comments Filter:
  • by RightSaidFred99 ( 874576 ) on Monday October 01, 2012 @05:43PM (#41518621)

    At this early stage it is difficult to see the development as good. It isn't particularly good for JavaScript developers who already have alternatives, and it isn't good for C# developers who now have confirmation that Ander Hejlsberg is looking elsewhere for his future.

    Lol, how cute. You're trying to create FUD.

  • by Anonymous Coward on Monday October 01, 2012 @05:43PM (#41518625)

    Stop trying to make JavaScript look like your favorite object-oriented language and accept it as is. It's a fantastic, flexible, un-bloated language that requires a different mind-set to master. Improve your JavaScript Engine performance and your DOM implementation, but leave the language alone. There is a reason why it's kicking so much ass. If you want strong, static typed and OO, go support ActionScript.

  • Clojure: []

    Don't think it's formally Google anymore.

  • by Anonymous Coward on Monday October 01, 2012 @06:05PM (#41518901)

    It doesn't replace anything. Its simply a higher level language that compiles to cross-compatible JS. And its open standard to boot.
    Not seeing any negatives about it. JS is a mess and MS is attempting to clean it up.

  • by MHolmesIV ( 253236 ) on Monday October 01, 2012 @06:08PM (#41518951)

    Exactly, it's basically a preprocessor for javascript that allows your IDE to help you write better code.

  • by Anonymous Coward on Monday October 01, 2012 @06:12PM (#41518977)
    It compiles to javascript moron. this doesn't replace javascript, it provides a better development interface to it.
  • Re:Full classes? (Score:3, Informative)

    by chromatic ( 9471 ) on Monday October 01, 2012 @06:15PM (#41519009) Homepage

    v8 (and other optimized JavaScript implementations) have decent performance despite JavaScript the language.

  • by Anonymous Coward on Monday October 01, 2012 @06:35PM (#41519199)

    c? to write client-side code run by the browser?

    are you high?

  • by exomondo ( 1725132 ) on Monday October 01, 2012 @06:47PM (#41519305)

    Once you start writing in TypeScript you are forever bound to Microsoft.

    I see you're unfamiliar with the concept of open source: git clone []

  • by aztracker1 ( 702135 ) on Monday October 01, 2012 @06:54PM (#41519365) Homepage
    Maybe because JS engines are more powerful these days than PHP? Maybe because the language primitives, and base functionality is far more consistent (not talking browser DOM)? Personally, I've been using Node.js for more and more, simply because it does the job so well, and leverages a language, that any currently working developer should probably have knowledge of.
  • Re:Full classes? (Score:4, Informative)

    by shutdown -p now ( 807394 ) on Monday October 01, 2012 @07:38PM (#41519797) Journal

    Doesn't JavaScript have a better system altogether? Prototypical inheritance? Classes feel awful in comparison.

    These classes are just syntactic sugar, and are fully defined in terms of prototypes and constructor functions. The exact translation is detailed in the language spec, but it's easier to just go here [] and see how exactly it maps TS code to JS code, live, as you type it. Here's a simple example with inheritance

    class Base {
        x: number;
        constructor(x: number) { this.x = x; }
        foo() { return this.x; }
    class Derived extends Base {
        foo() { return }

    translates as follows:

    var __extends = this.__extends || function (d, b) {
        function __() { this.constructor = d; }
        __.prototype = b.prototype;
        d.prototype = new __();
    var Base = (function () {
        function Base(x) {
            this.x = x;
        } = function () {
            return this.x;
        return Base;
    var Derived = (function (_super) {
        __extends(Derived, _super);
        function Derived() {
            _super.apply(this, arguments);
        } = function () {
        return Derived;

    As you can see, it's all fairly idiomatic JS.


    And doesn't the next revision have support for classes? I keep forgetting the name of it, H s... oh Harmony?
    I'm sure Harmony has a lot of things planned to extend the language massively to bring it up to standards even comparable to other languages.

    Indeed it does, and TypeScript classes are directly borrowed from there. Furthermore, the team has said that they will keep tracking ES6 (since it's still a draft), and amending TS accordingly so that their class syntax and semantics remain in sync.

  • Re:Full classes? (Score:4, Informative)

    by chromatic ( 9471 ) on Monday October 01, 2012 @08:13PM (#41520105) Homepage

    Coming from you?

    I know a little bit about compilers.

    Every language has its ugly spots that make optimization difficult...

    "Every number is a float" is one of them in JavaScript. "All objects are associative arrays" is another. "Object prototypes are mutable everywhere" is yet another.

    ... a large amount of the performance improvements that have come in recent years have nothing to do with the language syntax of javascript...

    Some, yes, but many also come from tracing the flow of data as the program runs to figure out which pessimizations inherent to the semantics of JavaScript it's safe to undo. That's why modern JavaScript JITs work so hard to perform side exits with their guard clauses to produce code that runs in as straight a line as possible. Ask Jim Blandy about it sometime.

    Perl would have to do similar optimizations. So would Python. So would Ruby. (It's instructive to talk to the people behind Rubinius and Unladen Swallow, if not people who've spent years optimizing Smalltalk implementations.)

  • Well, gaming consoles run JavaScript (in their browsers, or at least the Xbox will at some point), and most of them (PS3 being the exception) don't run Java.
    Smartphones run Javascript, while even Android doesn't really run Java (there are a few niche platforms that do, though).
    Every single PC has at least one, and probably quite a few, javascript engines (Windows ships with at least two: the one in IE and Windows Script Host). Neither Windows nor OS X ships with Java anymore.
    Aside from Windows-NT-based ones (again, Android doesn't count), I don't know of a single tablet that can run Java. They all support Javascript, though.
    Many dumbphones can run (a subset of) Java, but these days many of them can run Javascript too.
    Nearly all of the larget Personal Media Players of recent years can run Javascript; I don't know of any that run Java.

    In absolute numbers, I don't know what the balance is. However, in terms of the way that customers interact with their devices, Javascript is a lot more widely used than Java.

  • by thebjorn ( 530874 ) <> on Tuesday October 02, 2012 @02:38AM (#41522219) Homepage
    Python 3.3 didn't add a "yield" keyword, it added a "yield from" construct. Python has had "yield" since version 2.2. Python also has type annotations that "don't do anything": []
  • by Anonymous Coward on Tuesday October 02, 2012 @02:52AM (#41522269)

    And either doom the fork to incompatibility, or keep playing catch-up, while still being bound to Microsoft, like Mono.

"The pathology is to want control, not that you ever get it, because of course you never do." -- Gregory Bateson