474 points · by D_Guidi · 14y ago · 298 comments
* TypeScript is under the Apache 2.0 license [1]
* Source is available via git on Codeplex [2]
* Installation is as easy as npm install -g typescript [3]
Extra bonus coolness: They've provided an online playground like jsfiddle! [4].
[1]http://typescript.codeplex.com/license
[2]http://typescript.codeplex.com/SourceControl/changeset/view/...
http://blogs.msdn.com/b/interoperability/archive/2012/10/01/...
:set ff=unix
:wq
fixes for me
TypeScript seems very much in line with this trend, and I love it. This is exactly what I wanted - JavaScript but with decent safety and IDE support. And no more than that. I really hope that non-MS-geeks will embrace it and that Eclipse plugins and JetBrains tools and the likes will follow.
That said, ASP.NET MVC is a misguided and overrated Rails ripoff, IMHO. Where's all that great refactoring support if everything is made `dynamic` and stringly typed? What's up with matching parameters to method argument names? (I mean, change an argument name and your code breaks? wtf?) Since when does Microsoft tech favour magic over clarity?
Then again I'm biased. Their desire to sell insecure software to the US government when that was against the law lead them to deliberately destroy the life of a friend of mine who they were afraid was going to turn whistleblower to such an extent that he died and left behind a widow and small kids. (Example incident. At one point he got hired at another company, and his manager to be received a call from Microsoft whose whole point was, "How much do we have to pay you to fire him before he starts?" Microsoft knew how to be evil.) I'm not forgetting Ed Curry. Nor do I have any desire to forgive Microsoft.
As long as people associated with the worst of their excesses remain involved and in control - people like Bill Gates and Steve Ballmer - I will always make the non-Microsoft choice.
I don't think Microsoft tech has ever favored clarity...it's usually too java-esqe ivory-tower architeched enterprisey for my tastes. MVC is like that too, but the worst bits seem to be the ones inherited from ASP.NET. The new stuff is somewhat better, and you can now at least go look at the code to figure out how it works.
Also: MVC2 runs under NET 3.5 which doesn't even have the dynamic keyword. (I don't use dynamic in MVC3 or MVC4 either...)
The "stringly typed" (magic string) stuff was always avoidable. Regardless, see the [CallerMemberName] annotation and others which solves it back to INotifyPropertyChanged.
Now that the backlog of Microsoft tools have shipped, the scaffolding makes a bit more sense. The MVC team released multiple versions (open sourced!) instead of waiting for VS11. Which actually lines up with your core argument.
I completely disagree. ASP MVC may be inspired by rails, and C# inspired by java, and MS may be loathe to admit ether of those sources of inspiration.
however, ASP MVC on C# is great. Maybe because MS stole from the best.
IMHO.
Most of these have been around since MVC 1.0.
Hope these pointers will keep you magic string free :)
How evil a company is is directly proportional to the percentage of marketshare it has.
Contrast Dart and TS. Dart announced a year ago and they're only now dealing the JS interop issue, so to most people its still only really interesting as a play thing. TS announced and from the looks of if we choose to we can immediately start using it.
I know Dart is more ambitious and maybe long term their focus on issues other than interop will be proved to be correct, but I doubt it.
TypeScript doesn't have JS interop: it is JavaScript. TypeScript is basically JS linter with a type annotation syntax. (And a few additional local features like arrow functions and class syntax.)
That being said, we know on the Dart team that JS interop is hugely important. It's just much harder for us to do. We've just announced a big step in the right direction: http://www.dartlang.org/articles/js-dart-interop/
I do understand what you are saying, had read similiar on Dart forum in past. Just to be dear I am not in any way saying I think the interop would have been easy, I do think without it Dart was a dead end for most people. It will be interesting to see how things proceed, whether the interop story that is now available lets Dart finally take off a bit in terms of usage and mindshare.
Yes. Google (and others) need to stop releasing half-baked products.
You release something half-baked, even if it gets up to speed down the road, people will still have perceptions of it being half-baked. The above exchange is typical.
Now what I'd like to see in Javascripts evolution (non backwards compatible):
* Subract: Removing parts of the language - let crockford free to rip out the bad parts.
* Enhance: Bring in some more taste of Scheme.
* Replace: New scoping for var etc, without introducing new keywords.I'd prefer to change the semantics than introduce new keywords. Of course there are two schools of thought - I favour a small language over backwards compatibility. (And interim tools for migration).
Where I do favour extensions is for expressiveness or performance reasons.
Worth noting that the Azure SDK [1] was released on GitHub over a year ago with the same attributes. The move to Codeplex is concerning.
What's concerning about moving the location where Microsoft hosts their code?
I know that is a long answer, but I'd love a bullet point list of how if compares to the other javascript++ languages that have been coming out over the last couple of years.
Per the spec [1]:
TypeScript syntax includes several proposed features of Ecmascript 6 (ES6), including classes and modules.
[1] http://go.microsoft.com/fwlink/?LinkId=267121JavaScript is full of flaws, but its monopoly in the browser space has brought about one intriguing and welcome side-effect: a VERY efficient market for both employers and employees.
It's easy to overlook how important this common denominator has been for everyone involved. Employees have a tremendous amount of mobility within the industry: don't like your current JavaScript job? No problem - just about every dot-com needs a JavaScripter. Similarly, companies can today tap into a tremendous pool of JavaScript developers.
In today's fast-paced development environment, the ability to hit the ground running is key, and I worry that fragmentation will introduce unnecessary friction in the industry.
JavaScript is a wonderful language, deep down: It's Lisp-y, yet imperative. Its lack of support for threads has turned out to be a strength on the server side. And recent implementations have made it very fast.
People favoring node.js and compile-to-JS languages like Iced CoffeeScript to other server-side languages supports the fact that JavaScript itself is actually quite decent. At the end of the day, a language too broken could not easily be fixed with any thin compile-to-* effort, and most of the compile-to-JS efforts (with the notable exception of emscripten, whose goal is not to fix JavaScript) are quite quite thin.
[1] http://www.quora.com/CoffeeScript/What-are-disadvantages-of-...
ummmm, can someone elaborate? I don't understand that statement.
actually, i think one of the major flaws in the current programming job market is overrating the ability to hit the ground running. that leads to a dangerous level of short-term optimisation, where, say, you'd choose an employee who has experience with your current stack over someone with a better track record but requiring a month or so to learn their way around the specific languages and ecosystems involved.
It is always a bad idea to tie yourself too strongly to any single language.
Having said that, I'm pretty much tied to Java since 2000 and haven't seen anything wrong... yet. In fact, I'm determined to get better in Java everyday (memory model, JVM, concurrency, better design, etc).
Side note: I'm also learning pure "modern" JS just because there's no choice on the client-side.
Knowing Javascript, GWT is a win.
The fact that after all this time and efforts, ES6 won't be released for another year plus, speaks volumes about the "design by committee" thing.
It's also compounded because the majority of front-end developers write their code procedurally for each application component, which creates a terrible nest of repetitive and error-prone code.
They feel the pain, don't know how to solve it, so switch to a different syntax, blaming that as the root cause of the problem.
But feeling enough pain to viscerally HATE a language, as many front-end developers do, is not something that can simply come from the syntax of the language and the fact that the equality operator does type conversion and whatever small list of gripes users have. Most other languages (including CoffeeScript!) have a similarly-sized set of flaws and aren't nearly as derided.
As someone who has built large scale JavaScript applications, and has a lot of experience in other languages I really don't like JavaScript. My experience is that a lot of people know JavaScript, but very few people actually like it... Those people generally make writing JavaScript their day job.
Overall, cross browser js isn't really that difficult anymore and I rarely see people complaining about that. Of course, I've been part of the AltJS community for a while, and the people I follow closely are not front end developers.
A few of the weakest parts:
- for (var x in y) when used for array iteration or even dict iteration; hasOwnProperty? Really?
- x[obj] = y; seriously, did i really want '[Object object]' as my key?
- the choice of function level scope over block level scope
do ->
... local variables right here ...https://hackpad.com/spTEgxqvFYj#Things-That-Suck-About-JavaS...
I don't know of any JS developers that hate JS. I know a lot that hate some browser implementations of JS though.
I agree with everything camus said. Yes JavaScript has some cool stuff in it, but taken as a whole it is a pretty shitty language. This has less to do with the creation of JavaScript than it does the practical reality that JavaScript cannot really be changed in fundamental ways without immense amounts of politics. Pretty much the entire time JavaScript has existed it was due to be fixed in a couple of years, but then political fiasco after political fiasco (eg. EcmaScript 4) delays this.
JavaScript as you can use it today sucks pretty much as much as it always has, and is only tolerable now because there are some good libraries that hide the shittiness of the language from you. Wouldn't it be better to have a web language without such a shitty core, that didn't require 100k libraries to hide you from the terrible bits?
JavaScript has minor flaws but in general when understood it's outstanding. However it's not the style that you've been taught in school (OOP) and that's the problem for many newcomers.
It looks that you're just frustrated with something and want whole world to be as well, it won't work. Try CoffeeScript, it's much more approachable when coming from OOP world, then when you get how JavaScript works and understand it makes sense, you'll be ready to program in it directly.
It's easy to find JavaScript developers who love JavaScript solely because it's the only language they know. But once you start dealing with JavaScript developers who have a wider understanding of what various programming languages offer, the problems with JavaScript become much more obvious, and the hatred for JavaScript becomes immense.
I haven't dug much into it yet, but there are a couple of annoyances that i noticed in the playground that i wish will be corrected/alleviated somehow:
- The language is not expression-oriented. Once i got used to the "everything is an expression" mindset in languages like CoffeeScript or Ruby (or every functional language that i can think of) it feels quite tedious to "go back" and remember that, no, now the "if" is not an expression any more, you can't return it, or pass it to a function, or assign it to something. You can use the special syntax of the "?:" operator for an if-expression, but there is no equivalent for "switch", or "try", or "for".
- The type system doesn't seem to support parametric polymorphism. For example, the type of string[]::map is ((string, number, string[]) => any, any) => any[] instead of ((string, number, string[]) => T, any) => T[]. So the value ["hello", "world"].map((s) => s + '!') is of type any[] instead of string[], which would be preferable IMO.
NOTE: TypeScript currently doesn’t support Generics, but we expect to include them in the
final language. Since TypeScript’s static type system has no run-time manifestation, Generics
will be based on “type erasure” and intended purely as a conduit for expressing parametric type
relationships in interfaces, classes, and function signatures.
[1] http://go.microsoft.com/fwlink/?LinkId=267121http://typescript.codeplex.com/documentation
I like what they've done. Nothing too revolutionary, mostly adding static typing to Javascript without straying to far from the existing (or future) language or increasing the noise significantly.
Here's some highlights:
* Type inference
function f() {
return "Hello World!";
}
Will do the right thing* Explicit Typing
function f(s: string) {
return s;
}
* 'Ambient Types'To facilitate integration into existing JS libraries or the DOM, TypeScript lets you specify 'placeholders' for variables / classes that the runtime would expect to see e.g.
declare var document;
Almost a kind of dependency injection but also a neat way to manage talking to existing code.* Structural Typing
* Classes and Interfaces
interface BankAccount {
balance: number;
deposit(credit: number): number;
}
class CheckingAccount extends BankAccount {
constructor(balance: number) {
super(balance);
}
writeCheck(debit: number) {
this.balance -= debit;
}
}
* Modules module M {
var s = "hello";
export function f() {
return s;
}
}
* Arrow function expressions (x) => { return Math.sin(x); }Granted, there is no documentation that I could find on the website. I understand that this is a "preview," but I disagree with this way of presenting a tool. When the Closure Library was released, for instance, it was absolutely chock full of API documentation. This is because it was used for real-world projects and extensive docs mattered, even internal to Google.
There is a language specification (PDF, in the source tree) which is encouraging, but where's the manual? <http://www.floopsy.com/post/32453280184/w-t-f-m-write-the-fr.... The specification is largely a rewording of the ES5 spec with insertions where the typing additions are important. It will take a good bit for the reader to separate the wheat from the chaff, as they say.
I have more than a sneaking suspicion that this project is essentially a proof-of-concept, and that it is not heavily used at Microsoft. Do you remember "Microsoft Atlas" in 2006, at the height of the JS DOM Library Wars? In the end, they just pushed their developers to use jQuery with some code generation helpers. Microsoft's open-source track record for JavaScript is not impressive, and I think you'd be a damned fool to invest in this technology for any serious project.
I have more than a sneaking suspicion that this project is essentially a proof-of-concept, and that it is not heavily used at Microsoft.
My team has been dogfooding TypeScript for several months now, providing lots of feedback and writing > 30,000 lines of code (in many cases the new TypeScript code is shorter than the original Javascript).Further, how can you have a tool like this and nothing for generating type-aware documentation from your source code? Google uses jsdoc-toolkit, so this is a moot point for them. Either you guys are using this in an informal fashion, or documentation isn't that important at Microsoft, or you just haven't released the doc generation tool(s), which would be a really odd choice!
And TypeScript is just the language, so there's no API to document besides what your browser exposes in JS.
[1] http://www.typescriptlang.org/Content/TypeScript%20Language%...
It'd be 100% more useful if it was more aware of nullable types -- as it is, it appears that
null * 7
compiles without any error messages. If they add a "nullable number" type distinct from "number", I'll be a lot more likely to use it.It also appears that some other things compile that perhaps shouldn't, such as
7[2]
and 7["a"]
even though (7).a is equivalent and (correctly) fails to compile.Detecting null expressions at compile time might help. There are "nullable" types, but afaik only in signatures:
foo(x?) {
alert(x);
}
If `x` is not passed in, it will be `undefined`.Having optional variables is similar, but not the same as nullable types, especially when the compiler can't enforce non-nullable-ness. All JS devs are familiar with the annoying error "'null' is not an object" (and anyone who's programmed in a language like Haskell, OCaml, or F# knows the value of sophisticated compile-type type checking).
var s = 'foo';
var l = s['length'];
// type of l is `string`
I also agree about non-nullable types, and I've found even with TypeScript, having to make sure your vars are defined and not-null is still a pain.http://typescript.codeplex.com/SourceControl/changeset/view/...
- It's a superset of JavaScript. So there is no porting effort needed. (With CoffeeScript, you do not need to port if you don't want to.)
- compile-time type checking, like type erasure in Java's generics.
- module support at the language level. It's very thin. It does not give your AMD or CommonJS module, but you can easily hack around it.
- class and inheritance support at the language level. The implementation is very similar to CoffeeScript's.
TypeScript implements modules that are closely aligned with those proposed for
ECMAScript 6 and supports code generation targeting CommonJS and AMD module systems.
It also looks like you can consume CommonJS and AMD modules using familiar constructs. (x) => { return Math.sin(x); }
and modules, which are implemented using the immediately invoked function expression pattern: module M {
var s = "hello";
export function f() {
return s;
}
}
Syntax seems more clear than CoffeeScript and tool chain will probably shape up better. Looking forward to seeing this get some traction.1. Lambdas (as you mentioned) are not only shortened syntax, but also capture the `this` variable automatically for you. Try typing in the following at the playground in the body of the `greet` method to see what I mean (http://typescriptlang.org/playground):
var x = a => this.greet();
2. Classes with inheritance are a big one, implemented using the IIFE pattern as well, with support for static and class members.3. Interfaces with duck typing are very lightweight and easy to use:
interface IGreeter { greet(); }
class Greeter /* implements IGreeter */ {
greet() { ... };
}
4. Extensive type inference. In the following example, the function greet will be typed () => string: class Greet {
greet(x: number) {
var s = ' greetings';
return x + s;
}
}
Static and member vars, return types, local variables, all are type inferred.5. Javascript is TypeScript, just without typing, so converting your codebase is instance, and then you can begin adding type annotations to get more robust checking
var names = people.map((p) -> return p.name);
(or something along those lines). Funnily enough, it reminds me of C#'s LINQ: var names = people.Select(p => p.name); from([1,2,3]).select(n => n * n).where(n >=2).toArray()
which outputs [4, 9]
Hoping to open source it soon.Edit: typo, n * 2 should have been n * n, sorry for the confusion
_.chain([1,2,3]).map(n => n * n).filter(n => n >= 2).value()EDIT: they've got syntax highlighting for some other editors, but full completion and error reporting is still needed http://blogs.msdn.com/b/interoperability/archive/2012/10/01/...
There's a pretty impressive demo here: http://www.typescriptlang.org/Playground/
It even has auto-complete if you press "Ctr-Space" while typing a word. Considering the source for all this stuff is freely available, I don't think it'll be too long before other IDEs support it.
How do they map errors thrown in the browser, to TypeScript code? If this has things like classes and such, the relationship isnt always going to be 1:1 and debugging can become a nightmare. Part of what makes javascript so great is how easy it is to debug. All these "superset" languages that compile to javascript fail hard @ debug support usually
[1]: http://www.html5rocks.com/en/tutorials/developertools/source...
I would think microsoft wouldnt want to release this until source maps were tested, working and included as part of the language as a major bullet point feature. These languages are nothing but a novelty to use in prototyping until that happens. I'll never use any of these languages in my production development workflow until proper debugging is available.
"Why is [Microsoft] putting time and effort into
changing JavaScript when the DOM is what needs fixing?"
https://twitter.com/jeresig/status/124114331616026624The DOM simply is a poor abstraction for applications. For example, it doesn't have a concurrency model and many modifications to the styling of individual elements or changes to the DOM structure can cause repaints and reflows.
Another huge advantage is that the typescript parser & compiler is written in Javascript. Closure's jscomp is Java, which decreases backend portability somewhat.
Haven't we come to a consensus that types are more trouble than they're worth? They hurt clarity and catch few bugs.
Pretty sure we haven't. That shitty languages with shitty type systems are mor trouble than they're worth yes, but types?
Same with Objective-C and my iOS and Cocoa development (since the OpenStep days).
I do use Scala on the server side though, and it helps there. But application development is, IMO, hindered by static typing. It's a lot more work to set up, and provides essentially zero benefit.
And I love static type analysis (I use it with C stuff all the time). +1
I would also argue that static typing provides a self-documenting benefit that is easy to forget, making it easier for someone unfamiliar with the codebase to understand what is going on. When I'm doing maintenance work I often start at the point of failure and work backwards, and it is very helpful when I can immediately identify what a variable is supposed to be representing.
Common things such as access an undefined variable or property or trying to call a method of a null object would be detected by most static type checking algorithms.
If you see the compiler as your friend then you tend to like type checking because it blocks certain bugs and typos. It won't let you run your code until they're fixed. If you see the compiler as your enemy, as a barricade that you need to get past, then you tend to not like static types. The compiler prevents you from seeing your code running immediately.
Obviously there's other benefits to each system but I feel like this is the more "gut reaction."
An alternative explanation is a dislike of overly verbose languages with terrible type systems (the poster child for this category being Java), and as a result of low exposure to better statically typed languages painting all of the category with a Java brush.
The code is hosted on their demo site; /Script/vs/editor/editor.main.js appears to be the main js file and has this notice:
/*!
© Microsoft. All rights reserved.
This library is supported for use in Windows Store apps only.
Build: 1.0.8514.0.win8_rtm.120711-1900
Version: Microsoft.WinJS.1.0
*/Recently, Microsoft has been pushing Javascript very hard (embrace) and now it looks like they've started the "extend" phase.
Luckily, no one really worries about them being able to pull off the "extinguish" part anymore... they just don't have enough market power these days.
EDIT: Yes, I conceede the fact that TypeScript is OS probably addresses most of these objections.
Re-reading late 90s M$ memes gets old after a time.
The question is whether they will do it in a propitiatory way or push it as an extension of ECMAScript and try to get other VMs to implement it.
"Asked whether Microsoft might do something to prioritize TypecSript in Internet Explorer, Lucco, the chief architect of IE’s JavaScript rendering engine Chakra, says no."
[1] http://techcrunch.com/2012/10/01/microsoft-previews-new-java...
interface person{
firstname;
lastname;
}
interface apple{
colour;
}
function hello(p : person){
alert("hello " + p.firstname);
}
var aPerson = {firstname: "joe", lastname : "blogs"};
var anApple = {color: "red"};
var foo;
if(true){
foo = anApple;
}
hello(foo);var x = "lol" - error found : http://pastebin.com/R1wqp0CS var x; x = "lol" - accepted : http://pastebin.com/0vc68RbY
If Google comes out with Dart, well, then there's no need for that. But it's ok for Microsoft to be secretly working on their own Javascript 2.0. Just sayin' - Why criticize Dart when you've just come with almost the same thing? :)
But snark aside, good job Microsoft. Well done.
But I agree it is another case of two-faced behavior, not in the way you suggest. The IE blog post against Dart rejects a "clean break" and TypeScript builds on ES6. That's consistent.
What is not consistent is how similar parts (but not all) of TypeScript are to ES4, which MS opposed vigorously. Time has passed and ES4 had its own problems, so bygones.
The only reason I wrote it was to prove to a co-worker who was "hating" on JavaScript that it IS possible to have a type system in JavaScript - if that's what you want. Its not the same end result but similar enough to warrant a mention.
Here's the repo: https://github.com/christopherdebeer/TypedFunc
new Greeter("World");
with new Greeter(5);
and it still works. What good is adding types to functions if they are ignored?This thing claims to be meant for "application-scale" JavaScript, and yet doesn't repair even JavaScript's most notorious error?
A suggestion to the authors. Purchase this book:
http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockfor...
... then go through the book with a fine-tooth comb, and every time it describes something as a "bad part" or an "awful part", delete or fix that misfeature in TypeScript.
$ t
command not found
clearly they could have named the compiler just 't' instead of the overly verbose 'tsc'. all those extra characters!! $ curl http://news.ycombinator.com/user?id=j
No such user.
Clearly you could have named yourself just 'j' instead of the overly verbose 'jon6'. All those extra characters!!Still - looks useful.
People keep making the same mistakes, if you let them.
No thanks.
It's the best of both worlds, IMHO.
In the interim, a simple library like underscore is quite succinct:
_.map([1,2,3], n => n * n)
With more library support you could even do infinite lists with something like this: _.generate(index => 1.0 / index);This is the first sign that they are "getting" 2012 developers and are back in the game with a vengeance. Hope it works.
Dart is mid-nineties MS by comparison.