News for hackers. Stuff that matters.
Re:TypeScript: a language for application-scale JavaScript d... by tlack on Monday October 01, 2012 @12:47PM (#4597987)
Weird that I didn't spot a friendly list of features.. seems to have some cool ones, like a shortened function expression (from the doc PDF):

    (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.
Re:TypeScript: a language for application-scale JavaScript d... by wingspan on Monday October 01, 2012 @01:09PM (#4598107)
Here are some off the top of my head:

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

Re:TypeScript: a language for application-scale JavaScript d... by untog on Monday October 01, 2012 @01:02PM (#4598070)
I like the shortened function form. I played around with CS for a while before going back to JS, but I do miss being able to do something like:

    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);
Re:TypeScript: a language for application-scale JavaScript d... by wingspan on Monday October 01, 2012 @01:14PM (#4598149)
I've written a LINQ style library for TypeScript that allows you to write something like this:

  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

Re:TypeScript: a language for application-scale JavaScript d... by spicyj on Monday October 01, 2012 @01:47PM (#4598360)
Have you used the popular library Underscore.js http://underscorejs.org/? The equivalent to your code in Underscore would be:

    _.chain([1,2,3]).map(n => n * n).filter(n => n >= 2).value()
Re:TypeScript: a language for application-scale JavaScript d... by wingspan on Monday October 01, 2012 @02:00PM (#4598425)
I did look at underscore when figuring out how to design the library, along with many JS LINQ variants (http://ianobermiller.com/blog/2012/09/19/linq-for-javascript...).

It should be pretty straightforward to provide Underscore bindings for TypeScript.

One big difference in the library I was working on is that it is lazy, and modeled after .NETs IEnumerable. Whether this is a good thing or not, I'm not yet sure.

Re:TypeScript: a language for application-scale JavaScript d... by sciolistse on Monday October 01, 2012 @02:23PM (#4598546)
I've made a lazy linq-like library for javascript in the past..

The problem i had was that the native array methods are rather fast while function calls (for moveNext) are quite slow, so i couldn't get a whole lot of speed out of it.

Newer javascript engines might be sufficient to offset that though.

Re:TypeScript: a language for application-scale JavaScript d... by wingspan on Monday October 01, 2012 @02:27PM (#4598566)
I tried to get around this by creating overloads of almost all methods when you are operating on an array. `each` for instance, has a standard implementation using moveNext, and then an array implementation using a fast for loop. In some cases you could even drop down to native function calls.
Re:TypeScript: a language for application-scale JavaScript d... by sciolistse on Monday October 01, 2012 @02:45PM (#4598655)
Sounds reasonable. Could be better timing now as well, what with server-side javascript having become popular. Good luck with the library!
Re:TypeScript: a language for application-scale JavaScript d... by colin_jack on Monday October 01, 2012 @02:09PM (#4598476)
As a .NET and JS developer underscore is definitely the secret sauce that means I don't miss linq at all. Lovely lovely little library.
Re:TypeScript: a language for application-scale JavaScript d... by Kafka on Monday October 01, 2012 @01:42PM (#4598321)
Could you please explain why it would output that?
Re:TypeScript: a language for application-scale JavaScript d... by wingspan on Monday October 01, 2012 @02:09PM (#4598477)
Typo, updated. Should have been n * n
Re:TypeScript: a language for application-scale JavaScript d... by murki on Monday October 01, 2012 @02:00PM (#4598420)
Wouldn't it output [4, 6]?
Re:TypeScript: a language for application-scale JavaScript d... by wingspan on Monday October 01, 2012 @02:08PM (#4598475)
Ah yeah, typo, updated.
Re:TypeScript: a language for application-scale JavaScript d... by tlack on Monday October 01, 2012 @01:03PM (#4598073)
Apparently ECMAScript 6 is considering some other forms of function literals as well: http://www.2ality.com/2012/04/arrow-functions.html
Re:TypeScript: a language for application-scale JavaScript d... by untog on Monday October 01, 2012 @01:04PM (#4598081)
Interesting. As the TC article stated, it seems like a lot of this is based on ECMA proposals.
Re:TypeScript: a language for application-scale JavaScript d... by baltcode on Monday October 01, 2012 @01:25PM (#4598223)
It's actually even shorter:

      names = people.map((p) -> p.name)
Re:TypeScript: a language for application-scale JavaScript d... by tlack on Monday October 01, 2012 @01:46PM (#4598351)
I wish Typescript would add "implied return of last statement" to the short function syntax! I love that feature in Erlang.
Re:TypeScript: a language for application-scale JavaScript d... by zem on Monday October 01, 2012 @04:19PM (#4599135)
that's the feature i'm most surprised they didn't add. coffeescript already does it, for instance.
Re:TypeScript: a language for application-scale JavaScript d... by ConstantineXVI on Monday October 01, 2012 @05:03PM (#4599328)
I'm getting the impression that TS is avoiding making too many dramatic changes to JS. Functions that return undefined in vanilla JS would suddenly return whatever happened to be the last statement; likely leading to unexpected behavior.
Re:TypeScript: a language for application-scale JavaScript d... by zem on Monday October 01, 2012 @05:07PM (#4599348)
i wonder how hard it would be for their compiler to catch the opposite case, then - a program using the return value of a function without a return statement. i think that was my most common bug when i was doing javascript programming, because all the other languages i was using at the time had implicit returns.
Re:TypeScript: a language for application-scale JavaScript d... by ConstantineXVI on Wednesday October 03, 2012 @03:53PM (#4609367)
Closure Tools will let you annotate your functions with a return type; their compiler will catch a function so annotated that lacks a return[0].

[0] http://sixlette.rs/snap/Closure_Compiler_Service-20121003-15...