Slashdot Mirror


TypeScript: Microsoft's Replacement For JavaScript

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).

32 of 488 comments (clear)

  1. What are google's two js replacements? by Bill,+Shooter+of+Bul · · Score: 4, Interesting

    Dart, obviously. But what is the other one? Anyone know what the article writer was talking about?

    --
    Well.. maybe. Or Maybe not. But Definitely not sort of.
  2. I am still busy with silverlight by superflit · · Score: 5, Funny

    Sorry..
    I am still busy with silverlight...

    Oooppss. that did not work....

    1. Re:I am still busy with silverlight by Anonymous Coward · · Score: 3, Funny

      In related news, I just released a game in HyperCard.

  3. CoffeeScript, Dart and this - screw it all by thetoadwarrior · · Score: 5, Insightful

    We have JavaScript and that's shit because no one wants to agree on anything. So what do we get instead? a dozen implementations or something that is in theory nicer but compiles to JavaScript. This is not a solution. It's a mess.

    Fix JavaScript or give us something like Python minus the dangerous bits in the browser.

    1. Re:CoffeeScript, Dart and this - screw it all by neminem · · Score: 3, Interesting

      Obligatory: http://xkcd.com/927/

      Note: please do not mod this post up. Yes, it is completely relevant, and funny, but I can't take credit for it. :p (On the other hand, I request it not get modded down just because you don't like xkcd, either. Relatedly, why the frell don't you?)

    2. Re:CoffeeScript, Dart and this - screw it all by Anonymous Coward · · Score: 3, Insightful

      It makes me cry whenever I hear JavaScript being used as an 'assembler'.

      CPU performance, memory usage, and power consumption be damned!

    3. Re:CoffeeScript, Dart and this - screw it all by Anonymous Coward · · Score: 4, Insightful

      Fix JavaScript or give us something like Python minus the dangerous bits in the browser.

      Full Python is a relatively heavy language (compared to, say, Lua), and I would be less than thrilled if all browsers had to implement a Python interpreter in addition to the Javascript interpreter they would still require for compatibility.
      Besides, Python is all dangerous bits.

      I think a lightweight virtual machine would be a natural successor. If they had done it in the 90s it would be a considerably worse legacy than Javascript was, but I think we're ready for it now.

      Some desirable properties would be:

      • - Implementable as a small and simple interpreter
      • - Implementable as an efficient JIT compiler
      • - The VM and the ECMAScript implementation should be able to share a JIT, e.g. by compiling scripts to VM, or a common immediate representation.
      • - Must share the DOM and APIs with ECMAScript
      • - A reasonably efficient ECMAScript implementation of the VM
      • - Programs specifiable as either text or binaries

      (LLVM bytecode is NOT suitable for this; it is first and foremost a compiler IR, and is not intended for cross-platform use.)

    4. Re:CoffeeScript, Dart and this - screw it all by neminem · · Score: 5, Funny

      Yeah, well, you sound like a... person who... isn't very good at comebacks.

      Also, your mom.

    5. Re:CoffeeScript, Dart and this - screw it all by aztracker1 · · Score: 3, Informative

      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.

      --
      Michael J. Ryan - tracker1.info
    6. Re:CoffeeScript, Dart and this - screw it all by cbhacking · · Score: 3, Informative

      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.

      --
      There's no place I could be, since I've found Serenity...
  4. Aside from Microsoft's history.... by catbutt · · Score: 4, Interesting

    ...theirs seems like the right approach. It is certainly a better one than Dart. They've gone out of their way to be as compatible as possible, and really are making it practical for people to adopt the upcoming standards earlier. I really don't see what about this to get so up in arms about. Javascript does need improvements, and this is the best approach to that I've seen so far.

    1. Re:Aside from Microsoft's history.... by MHolmesIV · · Score: 3, Informative

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

  5. 0 day exploit found in TypeScript by logicassasin · · Score: 5, Funny

    I'm going to leave this here as a placeholder for the inevitable...

    --
    Fifty watts per channel, baby cakes.
  6. Re:Remember the old addage by MHolmesIV · · Score: 5, Insightful

    Rubbish. Not a good view of the technology. You might want to watch the channel 9 video and see how the language works before sounding the war horns. Essentially it's an overlay on javascript code that allows the developer to infer useful information about their code. The output from the "compiler" is bog standard javascript, no microsoft extensions at all.

    So if the "carpet" ever got pulled out from under you, all you would do is go back to editing the standard .js directly.

  7. Do you have a karma allergy? by Qubit · · Score: 5, Funny

    Obligatory: http://xkcd.com/927/

    Note: please do not mod this post up.

    Note: please do mod this post up

    --

    coding is life /* the rest is */
  8. Re:Full classes? by chromatic · · Score: 3, Informative

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

  9. Re:Remember the old addage by Anonymous Coward · · Score: 5, Insightful

    Embrace, Extend, Extinguish.

    Microsoft freely admits it, and when everyone jumps on the TypeScript bandwagon, the carpet will be pulled out from under you.

    How is this shit modded 'Insightful'? Karma whoring at its best, capitalizing on the nerd rage of geeks frothing at the mouth whenever Microsoft does anything. The fact is it is under an Apache 2.0 license, the spec is available and there are already 5 forks, so unless you have a fundamental misunderstanding of what EEE means you're just trolling.

  10. Re:all these languages what am I to do? by Anonymous Coward · · Score: 4, Informative

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

    are you high?

  11. Re:Remember the old addage by SplashMyBandit · · Score: 4, Insightful

    I think you are missing the point. While it is good the output is 'bog standard' Javascript what really matters is that the source is not 'bog standard Javascript'. Once you start writing in TypeScript you are forever bound to Microsoft. Now there may be compatible implementations but you may get a situation like C# where Microsoft's implementation is not only the foremost, but also the only complete one.

    They did a similar trick in years past with C++, where they had so many extensions that you pretty much needed for Windows development that once you started down their C++ path, forever would it dominate your project's destiny. These days their compiler will accept 'bog standard' C++, however to get real stuff done you still have to start using Windows constructs and interfaces (due to Microsoft producing APIs that look like like 'plain vanilla' C++; as many other APIs try to do).

    As others have pointed out, "All the roads lead to Microsoft, but none lead out".

    Now Microsofties could complain that the open source proponents are whining unfairly about this and it is resticting their, "Freedom to innovate". To that I say simply this, "How about you instead spend the effort on making your browser work like everyone else's?". The amount of workarounds and hacks required to compensate for the borked and agonizingly slow way that Internet Explorer handles (what should be) cross-platform Javascript is 'criminal'. The wastage in businesses and the entire IT industry caused by handling Internet Explorer's brokenness should make them blush. Sure, innovate and make the Javascript experience the best on Microsoft tools and platforms, but don't do it by creating more 'islands' than you have already.

    As others have pointed out, TypeScript may be tech flavor-du-jour for Microsoft at the moment (since they're trying to push their mobile solutions), but just like all their other tech it will have a limited shelf-life. You are better choosing truly cross-platform and long lasting tech for building solutions on. Historical examples: C#.NET (still used widely but not getting the Microsoft focus it once did), Visual Basic, COM/DCOM, OLE, C/C++ Win32 etc etc Yes you can still develop with these, but once upon-a-time they were the shizzle promoted by Microsoft and now people have to spend their time maintaining them with old and outdated tools. Meanwhile solutions developed with Standard C/C++, Java, etc get better tools and there are code changes required to maintain them are far more minor.

    Bet your solution on the long-lived tech stacks (and increase your long-term profits!).

  12. Re:Remember the old addage by exomondo · · Score: 4, Informative

    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 https://git01.codeplex.com/typescript

  13. Re:DEFINITELY No!!! by SplashMyBandit · · Score: 4, Insightful

    The probem isn't so much with C# the language/toolset. The problem is that in order for Microsoft to sell you new tools and tech it has to periodically change them just enough so you feel enough pain to shell out for new stuff. The other problem is that while C# is good for development it is clear that it is no longer an object of adoration in Microsoft's strategy. C# will always be around but it won't get the resources that the 'new hotness' team gets (eg. TypeScript). Meanwhile, those that use other tools (standard C++, Java etc) will keep plodding along, continuously evolving.

    If you know Aesop's Tortoise versus the Hare fable then this is what is happening now. Those who always watch the speed of the hare miss the fact that a new hare is entered into the race every few years. Meanwhile, those not distracted by the hare are watching the tortoise and see how it is less flashy but progresses continuously. If you built your tech on the tortoise you still have good solutions. If you build your tech with the hare then every few years you either have to rebuild your tech for the new hare (expensive! this is what CTOs worry about and code-monkeys don't), drop your existing investment and start building again for the new hare (expensive and wasteful), or stay with old tech (painful, and now surpassed by the tortoise).

  14. Re:Remember the old addage by shutdown+-p+now · · Score: 3, Insightful

    While it is good the output is 'bog standard' Javascript what really matters is that the source is not 'bog standard Javascript'.

    Most of it is actually bog standard ES6 (for example, classes). The only proprietary bit here are type annotations. Which you can ignore altogether if you want, and then you just get a free, open-source implementation of a convenient subset of ES6 that spits out ES5.

    Anyway, this is open source (Apache license), and the implementation is itself written in TS, and runs on Node.js. In other words, it is in no way locked into any existing Microsoft technologies, completely self-sufficient, and you can fork and mod it to your heart's content, on any platform. There is no way to "extinguish" it for Microsoft from this point on, nor control you should you choose to use it, now or in the future.

  15. Re:Full classes? by shutdown+-p+now · · Score: 3, Informative

    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 super.foo() }
    }

    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;
        }
        Base.prototype.foo = function () {
            return this.x;
        };
        return Base;
    })();
    var Derived = (function (_super) {
        __extends(Derived, _super);
        function Derived() {
            _super.apply(this, arguments);
     
        }
        Derived.prototype.foo = function () {
            return _super.prototype.foo.call(this);
        };
        return Derived;
    })(Base);

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

    Furthermore:

    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.

  16. Re:Remember the old addage by Tough+Love · · Score: 4, Funny

    Just keep calling it "ECMA Script" until it sticks.

    For some reason, "ECMA" always makes me think of "ACNE". Now it will for you, too ;-)

    You're welcome.

    --
    When all you have is a hammer, every problem starts to look like a thumb.
  17. The problem is not with Javascript by Hentes · · Score: 4, Interesting

    Javascript works well for what it was intended to do: adding dynamic functionality to webpages. It only has problems when it's used for something it was not intended to do like building web-based applications or the Flash-like animations of HTML5. These are very different use cases, and I don't think one language to cover them all is a good idea. Developing new languages for the new web technologies is the way to go.

  18. Re:Full classes? by chromatic · · Score: 4, Informative

    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.)

  19. Re:Remember the old addage by Anonymous Coward · · Score: 5, Insightful

    Is it just me or are the MS shills getting even more stupid?

    When Apache 2.0-licensed, publicly available (on Git), already forked code is somehow getting you "locked in" and "manipulated to be incompatible" i think it's safe to say the stupidity lies with all the anti MS morons with their senseless EEE rhetoric. Although given you think pointing out that this is about as open as it can get which makes it the exact opposite of "locking people in" is being a "shill" you're probably not much different.

  20. I call for web byte-code by devent · · Score: 5, Interesting

    So can we finally have a specification that is not bound to a specific implementation? Why in all what is good and holy, do we need the limitation of JavaScript? Just make a byte-language specification, just like the CLR or Java Byte-Code for the DOM stuff.

    Then everyone are free to use Python, Ruby, Java or what else as a language, the browser needs only to interpret the Byte-Code that the language-compiler is producing (just like with Java and javac, where you can use any language you like to produce the Java byte-code).

    If you are really worried about open source, then answer me this: What is the difference between this and byte-code? There is none, because both are not human-readable. So why not just to agree to a byte-code that interfaces the DOM and html5 and then we can use any language we like to generate the byte-code?

    Wouldn't it be nice to fire up your favorite IDE or editor and just write Python or Ruby (or insert here your favorite language) for your web-page? But no, we just have to use JavaScript until the end of the universe.

    PS: most browsers are compiling JavaScript to a byte-language anyway nowadays, because then they can optimize the byte-code so JS will run faster.

    --
    http://www.mueller-public.de - My site http://www.anr-institute.com/ - Advanced Natural Research Institute
  21. Re:Remember the old addage by jbolden · · Score: 3, Insightful

    research.microsoft.com has been advancing lots of open source functional languages that use type inference and no one has been getting burned. The research group lets them do cutting edge research and then another research group builds an implementation for more mainstream languages and then it gets pulled in by product management.

    So I'd say in the open source language arena the public has learned the opposite.
    I'll agree it is different with products as opposed to technologies.

  22. Re:Remember the old addage by exomondo · · Score: 3, Insightful

    He means in the 'dictating policy and direction' way.

    But that wouldn't make sense because the beauty of open source is that if you don't like the direction that the project steward is taking it in you can just fork it, simple.

  23. Re:Remember the old addage by thebjorn · · Score: 4, Informative

    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": http://www.python.org/dev/peps/pep-3107/

  24. Re:Remember the old addage by cant_get_a_good_nick · · Score: 3, Insightful

    He means in the 'dictating policy and direction' way.

    People here forget the concept of Opportunity Cost. Everything costs you some resource: Time, money, brain nurons, carbohydrate energy in your blood, at least something.

    I use a simple text editor because I don't want to learn Emacs. I don't decry the tyranny of Emacs, of the evilness that is Stallman locking me into a particular set of key sequences. Oh my deity! Stallman is dictating policy and direction for my text editor!! I just say "I don't want to spend my energy there".

    Everything pushes you to a direction. Microsoft does. JavaScript does. ECMAscript does. C does. C++ does. Scheme does. If you're worried that the direction Microsoft pushes you leads to a bad path, fine. But don't kid yourself that by choosing something else that you're no longer being pushed.