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).
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.
Sorry..
I am still busy with silverlight...
Oooppss. that did not work....
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.
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.
Bullshit. Look at other languages that compile to JavaScript that also don't pollute the standard:
https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS
The summary is just wrong. JavaScript isn't being replaced. It's being enhanced in an entirely compatible and most importanly voluntary way.
...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.
I'm going to leave this here as a placeholder for the inevitable...
Fifty watts per channel, baby cakes.
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.
Obligatory: http://xkcd.com/927/
Note: please do not mod this post up.
Note: please do mod this post up
coding is life
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.
Um, the Apache License is significantly more free than the GPL. Just sayin'.
v8 (and other optimized JavaScript implementations) have decent performance despite JavaScript the language.
how to invest, a novice's guide
Actually C# is a great platform for RAD. Just because it's MS doesn't mean it is always shitty or evil. It isn't on the 5th place of most used languages because it sucks.... Lots of pro's are using it and many a serious C++ picks C# for fast prototyping and development. It's all about knowing what tool to use for what task. http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
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.
c? to write client-side code run by the browser?
are you high?
Agree, I can't see how anyone is any more 'locked in' to this than they would be if they used say Google Dart.
Beyond that, a lot of it seems to line up with the EcmaScript6 work in progress spec, and Anders seems to be interested in re-aligning to that spec as it moves forward. What I found really interesting above everything else, is that it's an npm (node.js) module, and runs from node.js, not WSH, or some other bastardized environment. As I am working on publishing a JSON web service currently, I already have my object definitions documented in a JSON structure very similar, and may just adjust them all to *.d.ts, since it's fairly obvious the intent. I'm still testing using the newer WebAPI from MS, or simply going Node.js for the API service itself... leaning towards node + mongo... but the option seems fairly clean, and open.
.d.ts files out of coffee-script declarations for classes as well, so that it can be more interoperable. It would also be nice to see other IDEs adopt the idea. I think JS interaction, and intent of code (documentation, and interaction) is the most difficult thing, which this works to resolve... Though it does remind me a lot of ES4/AS3.
I just hope it doesn't wind up another also ran.. It would also be nice to get
Michael J. Ryan - tracker1.info
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!).
Because they don't understand how prototype based inheritance chains work, or how to utilize functional programming techniques. When you add event driven callbacks, along with non-class based structures in JS, it can be very elegant, and with Node.js + async, far more performant than other solutions..
Michael J. Ryan - tracker1.info
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
Just keep calling it "ECMA Script" until it sticks.
Good luck.
Required reading for internet skeptics
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).
Exactly this. Another attempt by microsoft to comandeer a standard and lock people in as they manipulate it to be incompatible.
Well, I think the only proprietary parts MS added to JScript are creating an ActiveXObject, which lead to XmlHttpRequest... And an enumerator for dealing with ActiveX... the language itself was a pretty compliant implementation.... now proprietary and excessive use of the former on many websites was a large problem.
Beyond that, this is a lot different. This is a set of declarative extensions to JS that lean towards the next version of the standard and act as a pre-processor straight to JS proper. Not only that, but the license is open, very permissive, and uses a non-ms runtime environment (Node.js/V8) for the "compile".
Michael J. Ryan - tracker1.info
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.
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
translates as follows:
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.
Probably one of Go, Closure, Java (via GWT), or C (via NaCl), though I suppose one might see Python and (again) Java (this time, via AppEngine) as "replacements" for server-side JavaScript in the form of Node.js, though that's even a bigger stretch than the others. Dart is the only one that is actually an effort in the direction of a general JavaScript replacement, though.
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.
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.
I know a little bit about compilers.
"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.
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.)
how to invest, a novice's guide
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.
Public has entered the enlightened stage of not taking _anything_ from Microsoft - open or not. Common sense now says there is or will be a catch to it and anyone who takes it will regret it. That is what happens when people get burned repeatedly. They learn. Astroturf this away if you can :)
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
That still doesn't make any sense. There's no implementation to install here - TypeScript compiler outputs portable, standards-compliant JavaScript code that runs the same on any browser (and also Node.js etc).
You cannot ignore the annotations if the majority of libraries you are attempting to use are 'tainted' with them.
Sure you can. You just run the TS compiler on them, get JS output, and stick to that. It's quite intentionally outputting well-formatted JS that very closely mimicks the original code - to the point where language spec itself defines how exactly transformation happens. Right now it's not comment-preserving, but they intend to change that, too. This all will work much better once they start targeting ES6 directly, rather than ES5.
Also note that annotations are purely compile time hints (for warnings, IDE tools etc), they do not change runtime behavior at all. So you can indeed strip every single one without changing semantics.
Now, if Microsoft were actually going to do something to improve the Javascript experience they would spend effort into make Internet Explorer work like the other browsers (which, despite pitiful resources, manage to be roughly similar in behaviour) and make it run fast (there are some Javascript operations in IE that are 100x slower than its competitors). I'm suggesting a 'profile guided optimization' here; leave Javascript/Ecmascript alone for now and fix the real point of pain of Microsoft tech on the web/mobile; the Abomination that causes Desolation, and premature aging of web devs (otherwise known as Internet Explorer).
Admittedly I don't know much about the current flock of issues with IE - not being a web developer - but from what I've heard, IE9 was a massive improvement on IE8, and I've heard good things about IE10 as well - I wonder if your "100x slower than competitors" still applies there?
There is certainly a team that focuses on its JavaScript engine alone, and perf is a major issue for them. TypeScript, on the other hand, is an altogether different team, and people there focus on much different things (for example, runtime perf really isn't their concern - they just produce idiomatic JS, and leave it to the implementation to handle it right). That's why you see e.g. Anders Hejlsberg there, who is the local language design guru. I'd expect JS runtime team to be similarly stuffed with people who have considerable experience with JIT compilers and such.
Rather, it seems MS is trying desperately to become more relevant and trustworthy in the open source space. So much so that they will toss their hat in the ring any chance they get.
Javascript seems like a good opportunity, if you're looking at it from their perspective.
Someone flopped a steamer in the gene pool.
Sticking with C.
And now you don't have to be left out of the web page revolution... Check out https://github.com/kripken/emscripten/wiki which is a LLVM backend for javascript. They have ported a big portion of the standard C libraries, STL, and a number of other things. Its pretty funny, but you can run boat loads of old emulators, games, you name it in a browser now.
I know, it's a good thing nobody is trying to get that popularized.
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.
C# .NET is historical? Really? Last time I checked MS *just* released .NET 4.5 and C# 5.0. Not to mention C# has been on the *cutting edge* of language design for years while Java is stuck in development hell.
That "yield" keyword that Python 3.3 just added? Guess what mainstream language they got the idea from? The lambda syntax ECMAScript 6, C++11, and CoffeeScript use? Guess where that came from? Hint: NOT Java, Python, Ruby, PHP, Perl, or other open-source language of your choice.
Just wait a few years and watch at how many languages add an "async/await" feature.
If you want to dick measure... where do you think C# got its core constructs from? Intelligent aliens? EVERYTHING has come from open-sourced languages... you don't GET where C# is (or Java for that matter) without Lisp, Scheme, etc. Hell, Lisp had if/then/else constructs before ANY other language... it didn't come from IBM, either...
It's the Stay-Puft Marshmallow Man.
The type annotations/inferences are features that would have been in ES3, had it not been tanked by committee.
HAL 7000, fewer features than the HAL 9000, but just as homicidal!
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.
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/
And either doom the fork to incompatibility, or keep playing catch-up, while still being bound to Microsoft, like Mono.
And how about patents? Would you bet against me if I said that Microsoft had a bunch of patents pending related to TypeScript?
They released it under the Apache 2.0 license so patents aren't an issue, moreover typescript just emits javascript so the end result that is actually used is just plain javascript anyway.
If you're going to criticize something, at least get your facts straight. The C# yield keyword has nothing to do with Thread.yield(), it's for easier implementation of lazy iterators. And there is a very good reason why it is a feature of the language: it actually changes how the method behaves at a fairly deep level. Upon hitting the yield keyword, execution leaves the method and returns there only when another item from the iterator is requested. That's why it can't be just a library.
If you are familiar with the Apache 2.0 license you would know it doesn't matter.
I think I can see what the business plan is:
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.