TypeScript 0.9 – What’s Improved
flippinawesome.org
flippinawesome.org
edit: oh, and tooling, but I'm not normally on Windows for development so I haven't played much with the Visual Studio integration.
More importantly, types can go well beyond catching errors or tooling. Types can actually make your code more expressive and they can push your design forwards.
For the first, the simplest example is with Haskell's typeclasses: you can't easily write something like Show or have something like Haskell's flexible numeric literals without types. This allows you to grow[1] Haskell in ways that are even difficult in Lisp! For a more practical standpoint, I've found certain libraries to be much harder to reproduce without typeclasses, most crucially QuickCheck.
The second idea is slightly more abstract. As somebody else put it, types are like gravity sources: we place them strategically in our design space, and the rest of the code falls towards them. More concretely, coming up with the types to represent some domain often really helps in writing the code for it. Sometimes, once you've got the general framework of the types, the actual programming just feels like systematically filling in the blanks. More generally, the effect is nowhere near that pronounced, but the types do help shape everything else. In a sense, types help you constrain the set of possible programs at the outset, giving you fewer options to consider as you go along.
Oh, and I guess there's the performance thing. This includes both low-level optimizations (C++ or even C-style stuff) and high-level ones (like rewrite rules). Optional type systems seem to give up on these as a matter of principle. I don't believe static types are strictly necessary for good performance, but empirically they seem to help. Most languages with really good compilers are statically typed.
I think the idea that types just exist to catch type errors is one of the most unfortunate common misunderstandings about type systems. It really scares people away before they can learn about all the other benefits a good type system confers.
[1]: Okay, not really uniquely, but it's close. I've seen Hoogle-like tools for OCaml but not for Java or C++, much less something like Python. I'm not sure how useful or general they could be for other languages.
[2]: Easily my favorite CS talk: http://www.youtube.com/watch?v=_ahvzDzKdB0
The thing that's been really nice is the ability to write a certain amount of ES6 style code (eg using arrow functions to lexically bind the this value) and having the TypeScript compiler transpile that into ES5 / ES3 JavaScript.
I really like it. I think the tooling is still a little rough but it's still in Alpha so that's fair enough I guess. It'll improve.
The only thing I dislike about TS is the way it handles dependencies. The require/declare/import/export methodology confuses me. And on top of that there is the //<reference /> tag, and all of it seems to be relying on files, rather than on constructs in the code. Relying on files, means that I have to maintain the order of which to import what, and this becomes even harder if some of the files contain code that is not just module/class definitions, but actual statements in global scope.
So you're left feeling confused because there is more than one way to write a program. Options are good and all, but in the front-end Javascript community, I think we could deal with fewer of them.
To solve your own problem: I would recommend using CommonJS with Browserify for everything, and only use reference tags for ambient declarations. (.d.ts files). Then you'll always use import and export
Is there a guarantee that TS will remain a strict superset?
Looking at the syntax, it reminds me of Flash ActionScript, which started out as an ECMAScript implementation but became an incompatible superset that pretended to be JavaScript compatible but would whine endlessly about untyped var declarations...
Hopefully ActionScript and C++ will serve as warnings to TypeScript designers: if you're ever thinking about disrupting code compatibility with the original language in the name of added type safety, don't do it.
var x = "".constructor(5);
// The property 'constructor' does not exist on value of type 'String'.
The exceptions make sense if you dig into how the type system works. AFAIK these can always be worked around with an explicit cast to any: var x = (<any>"").constructor(5);
I've found TypeScript to be a huge win for maintainability, and can't imagine going back to raw JS for an app of any complexity. I'd love to have a chance to pair it with Node for something.