TypeScript: Design-Time tool for Application-scale JavaScript development

http://www.typescriptlang.org

TypeScript starts from the syntax and semantics that millions of JavaScript developers know today.

With TypeScript, you can use existing JavaScript code, incorporate popular JavaScript libraries, and be called from other JavaScript code.

TypeScript compiles to clean, simple JavaScript code which runs on any browser, in Node.js, or in any other ES3-compatible environment.

TypeScript offers classes, modules, and interfaces to help you build robust components.

These features are available at development time for high-confidence application development, but are compiled into simple JavaScript.

TypeScript types let you define interfaces between software components and to gain insight into the behavior of existing JavaScript libraries.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Microsoft's Dart?

Is it fair to call this Microsoft's Dart?

No

If Dart was a superset of JavaScript ad supported existing JavaScript libraries, us, but dart doesn't...these languages are targeting completely different things. Typescript seems to be more like coffee script with more static typing.

No "No"

I agree the form is very different, and being easily compatible with Javascript is surely a major advantage of Typescript in terms of adoption potential (and also a relative downside in terms of which semantics aberration it will protect us from).

Yet I think it's fair to say that they have the same purpose: making "large-scale" programming possible in client/server Web scripting languages. From that I disagree with your assertion that they "are targeting completely different things".

My own prediction would be that Typescript is in position to completely obsolete Dart at this point (again a sign that they play in the same playground, rather than being orthogonal in purposes). I have mixed feelings about this, because I have both deep disagreements with Dart technical choices and deep respect for Dart design team and their choices, and because I feel that if Dart is to fail it will also be for "political reasons" (Mozilla and Webkit refusing to consider Dart at all) that are not as noble as technical considerations. Finally, TypeScript is yet another occasion to make (well-deserved) good publicity for Microsoft proprietary IDE toolchain, which creates cognitive dissonances between my programming language interests and strong support of free software.

So far, it seems that Dart focuses on performances, while TypeScript focuses on convenience and tooling for large-scale project (while in fact both can win on both sides). It will be interesting to see how people choose their camp.

One last remark: to improve performance, TypeScript implementors will have interest in adding enough low-level typing features to Javascript for it to become a better compiler target (through the ability to express stronger representation invariants). That's good for everyone. Dart-to-javascript has the same incentives, but Dart was also a move away, by a part of Google, from the trend to improve Javascript.

Yes then

I'll give you that they are probably going after the same cake, but the design approaches are completely different. Dart is a new language, typescript is more of a C++ move by taking a loved language and giving it more love in a backward/forward compatible way.

Visual studio isn't the end of the world for IDEs languages. We just need to get more busier at reinventing the language interface (i.e., go beyond smalltalk). from this perspective, typescript is boring, but so is its competition. At least we get intellisense, howver.

TypeScript is an

TypeScript is an optionally-typed, design time, syntactic layer over plain old JavaScript, providing classes, interfaces, modules for use in structuring large JS code bases.

Dart is Dart. It can compile to JS out of convenience (for obviously pragmatic reasons...), but it doesn't have to (and, really, it's best to take full advantage of the Dart VM, anyway, not JS engines, especially if you want to, say, write Dart applications...).

Regarding IDE adoption, it's still pretty early, but Cloud9 implemented TypeScript support for their browser-based IDE in a few hours. Nothing prevents more industrial strength IDEs (a la Eclipse) from doing the same over time. Even without an IDE, TypeScript is still useful.

I'll give you that they are

I'll give you that they are probably going after the same cake, but the design approaches are completely different. Dart is a new language, typescript is more of a C++ move by taking a loved language and giving it more love in a backward/forward compatible way.

I suppose my phrasing wasn't clear about whether I was asking about the cake aspect or the design aspect. You've answered both, so thanks!

Language Specification

More of the same

More of the same middle ages software development IMHO.

Since large-scale JavaScript

Since large-scale JavaScript development is squarely in the dark ages, moving to the middle ages is a good thing :-)

The TypeScript playground already has code completion support in pure JavaScript, so I can't imagine that functionality won't rapidly spread into IDEs other than Visual Studio.

The interesting question is whether TypeScript addresses enough of the needs of large JavaScript developers to pull momentum away from Dart. Dart has a number of technical hurdles in the way of wide usage on the Web. TypeScript has none whatsoever since it is really just JavaScript. I'm frankly surprised Google went with a bet on a new VM and whole new language in the first place; I would have expected them to get behind ES6 and go in a more TypeScript-like direction. TypeScript seems to be getting rapid uptake already, and if it covers the 80% cases well, it's not clear how much rationale Dart is left with.

(Disclaimer: I work for Microsoft.)

Since large-scale JavaScript

Since large-scale JavaScript development is squarely in the dark ages, moving to the middle ages is a good thing :-)

Wonderfully said.

I agree with your analysis of Dart's situation. Dart is still struggling to achieve momentum, I think. Competition like TypeScript will see Dart go the way of Silverlight. :)

Google and ES6

I'm frankly surprised Google went with a bet on a new VM and whole new language in the first place; I would have expected them to get behind ES6 and go in a more TypeScript-like direction.

Just to be clear: Google actively supports and invests into ES6, Dart notwithstanding.

JS code completion impl. implies widespread IDE support?

The TypeScript playground already has code completion support in pure JavaScript, so I can't imagine that functionality won't rapidly spread into IDEs other than Visual Studio.

Why do you think that that fact implies that adoption will happen quickly? I don't necessarily think adoption will be slow, but I don't see how Microsoft's JS implementation will speed things up, unless you're suggesting that many IDEs use JavaScript to implement code completion and that their frameworks for hooking into code completion are nearly compatible with what's used in the demo IDE on the TypeScript page.

It seems like IDE support is more related to how large and/or dedicated the sub-population is for a given language within a particular IDE's userbase. Actually writing the code to support a new language doesn't seem like the sticking point, especially when a grammar and specification is available.

No comments?

I would have expected more comments on this from the LtU crowd. Are people being apathetic about the sad state of affairs regarding javascript in general? Or the difficulties of new language adoption by the mainstream developers?

See this reddit comment, by

See this reddit comment, by a member of the Dart team, on technical differences between TypeScript and Dart as languages. The summary is that it made slightly different compromises from Dart, and I like these ones better (in particular the downcasting is not implicit, giving a bit of meaningfulness to the whole typing story).

Other than that, I wouldn't say that it's a terribly interesting language from a technical point of view: if you know about ActionScript 3 (as a previous attempt to type-annotate Javascript) and Dart, there is not much innovation to comment on -- that's not the goal of the tool.

I'll note that there are no generics, and that they made the same choices as the Go team in this respect (hardcoding generics for some datatypes of the standard library).

There are things to say about the way some of those choices will help adoption (in the Socio-PLT spirit), and also how it will influence the evolution of the whole Javascript ecosystem. My sentiment is positive, and in particular I hope that closeness to Javascript will help retrofit some of the work into the Javascript standard, with accelerated uptake due to the existence a successful implementation of those ideas. If we can get decent optional typing in Javascript in 3 years rather than 10 because of this, this will already be a very good thing. I'm not sure those political aspect are the kind of comments one expect to find on LtU.

Politics? Now I can't get

Politics? Now I can't get rid of the image of Jim Lehrer moderating a debated between static and dynamic typing. Only thing for sure, Big Bird ain't going to be too happy with the result.

It's been so long since

It's been so long since something like The Treaty of Orlando, somehow we've separated into our own like minded communities and these debates don't really happen that much.

You realize that The Treaty

You realize that The Treaty of Orlando was never the topic of a home page story? Where are all the OO advocates when we need them?

if you know about

if you know about ActionScript 3 (as a previous attempt to type-annotate Javascript) and Dart, there is not much innovation to comment on -- that's not the goal of the tool.

Just a nit on phrasing: it really helps to separate invention from innovation! TypeScript focuses on diffusing basic PL inventions to the browser app crowd rather than making new ones. I bet they could do more in how to do that both in terms of invention and innovation, but it's great that this is being done for more than basic syntax etc. (a la CoffeeScript).

I'm happy to see this. I

I'm happy to see this. I think TypeScript could offer a very good path for improvement for JavaScript. Distribution with node is an excellent idea. But I... can't say I'm excited about it. I wonder why that is?

(edit: I'll add that the module system is more interesting to me than the type system.)

Relevant

See Jeremey Siek's take on gradual typing in TypeScript.

Interesting

Thanks, it's interesting.

I regret I discovered in this blog that function input types can be both contravariant and covariant in TypeScript. I had only read that they didn't allow implicit downcast at assignment, and had assumed downcasting at call site similarly required an explicit type assertion¹. I'm disappointed that functions input types are covariant, and at a first uninformed glance it seems to me that those two different design choices are inconsistent.

¹: note that type assertions are erased by the type-checker, and in particular don't result in any form of runtime check

Anders and Lars Bak Discuss...

Here's Anders and Lars Bak discussing TS, JS and Dart. Filmed in Aarhus, Denmark a day after the TypeScript announcement. Interesting discussion.

Just watched this today

Most interesting part for me was Lars Bak talking about "Tree Shaking": A new buzzword for dead code elimination, seems related to a question I asked recently on StackOverflow.

Also, Anders mentioned TypeScript originally had a different version of classes, that he liked better, but they migrated toward ES6 max-min classes so that TypeScript could remain consistent with ES6. Does anybody know what TypeScript's original class system was like? Today, I spent a few hours reading discussion archives of Allen Wirfs-Brock, Dave Herman, Russell Leggett, etc. debating classes, but as an outsider, it was tough to follow, especially since I am a relative JavaScript newbie. I am guessing Anders is referring to Allen Wirfs-Brock's comparison between max-min classes and "enhanced object literals", but I can't say for sure.

Tree shaking isn't quite a

Tree shaking isn't quite a new word. It was used in this sense at least as early as 1994 in Jones' Dictionary-free Overloading by Partial Evaluation.

The first LtU language I use in a commercial app!

7 months ago, I would never have predicted using TypeScript. Like many, I am overwhelmed with the options for transforming code into JavaScript. Recently, somebody on our team introduced TypeScript. Here are my thoughts, while still being an incredible newbie, from the field:

1) This is the first JavaScript compiler I am comfortable using. Every other attempt has had strange corner-cases that could cost you days trying to understand how to create a work-around. With TypeScript, the code always compiles to idiomatic JavaScript, using best practices you might read about in LtU member Dave Herman's book Effective JavaScript.

2) IDE integration. There is a massive and rapidly growing community of developers who are creating "JavaScript header files" using TypeScript, and, as such, all the libraries we use at work have great IntelliSense support and static type checking. Admittedly, it took me awhile to get a feel for how this "magic" works, but it's simply awesome.

3) Semantics are basically the same. OK, JavaScript has some weird corner-cases, but at least I only have to worry about those. For example, Dart has recently removed support for window.setTimeout and replaced it with an idiosyncratic Timer object, which has different semantics from those given in HTML5 spec. Life's too short to have to debug your way through that caca. If you can, God bless you.

Those are the positives. Here are my perceptions about negatives, most of these are personal and don't apply to anybody but me:

1) I am not very good at keeping track of the latest and greatest from the EcmaScript 6 committee. Despite the fact Dave Herman, Sam Tobin-Hochstadt and Mark S. Miller are all forum members, there is almost no discussion on LtU about the upcoming modules feature, and since I get most of my programming language development news from here, I have no clue as to how well TypeScript will/can remain compatible with JavaScript.

2) I like the fact there is now a common idiom for "classes" in JavaScript, since many frameworks create this concept, such as Cappucino's Objective-J classes, Sencha's class system, Dojo's dojo.declare, and YUI's inheritance patterns. I kind of wonder if the path chosen by TypeScript team is the most flexible. I haven't thought about this in too much detail, since it has hit 100% of my use cases so far, but as I see places where I can DRY up my code, I anticipate wanting something fancier.

3) TypeScript doesn't seem to do any deadcode elimination currently, although it does support RequireJS via AMD compiler switch, which in turn depends on Google Closure Compiler. How's that for a huge compiler dependency? :) I asked about this on StackOverflow, but haven't gotten any useful answers so far.

I hope this real-world user feedback is instructive to other language designers, who want to create similar languages.

classes considered harmful no more?

does the rise of "classes" in javascript mean that prototype approaches are wrong, or that people are too dumb to use them right, or that there's a time and a place for either approach even in one language?

Primitive composition operators

Ideally, we could build languages using primitive composition operators and compose compound composition operators from those primitives.

But, more practically, the argument for max-min classes seems to be (from my reading yesterday) that they make the code a little easier to understand, and also more uniform. Main example would be passing "self" references from a parent scope to enclosed child scopes.

As for judging other's intelligence, no thanks. The "too dumb" argument generally is the wrong way to think about why complex systems fail. Reading the comments by the EcmaScript committee members in the archives yesterday, it is good to see they all seem to share the right perspective on resilience engineering for language design.