Live data from Hacker News

TypeScript: a language for application-scale JavaScript development

typescriptlang.org

41–50 of 316 posts

Re: TypeScript: a language for application-scale JavaScript development

#41
post #38
post #37

Earlier quoted context omitted.

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);

Apparently ECMAScript 6 is considering some other forms of function literals as well: http://www.2ality.com/2012/04/arrow-functions.html

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 development

#42
Very interesting. The Apache 2.0 Licence is comforting, makes it worth having a look. The docs are here for anyone interested in the spec:

http://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); }

Re: TypeScript: a language for application-scale JavaScript development

#43
post #18

Back in the day, Microsoft would use a strategy called "embrace, extend, extinguish." http://en.wikipedia.org/wiki/Embrace,_extend_and_extinguish 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 day…

This would still be the "embrase" phase. Extending is when they add a new feature that doesn't exist and isn't supported by the competitors. As soon as you see it compile to a flavor of JavaScript that only IE understands - then will the "extend" phase have begun.

Re: TypeScript: a language for application-scale JavaScript development

#45

Awesome, great to see this finally released. I'm a dev in FUSE Labs ( http://fuse.microsoft.com ) and we've been dogfooding TypeScript for a while now. I'd be happy to answer any questions about using TypeScript vs vanilla JS, converting a large codebase, etc.

I'm wondering how to make use of an existing object system. We already have a JS framework that simulates classes and inheritance in the Java-style OOP.

Re: TypeScript: a language for application-scale JavaScript development

#47
post #14

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. L…

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 development

#48
post #23
post #15

I've written a lot of JavaScript, including large-scale projects, and never once have thought, "Gee, I wish I had type checking." Haven't we come to a consensus that types are more trouble than they're worth? They hurt clarity and catch few bugs.

No, we have not. Read John Carmack's posts on static code analysis to understand why.

I've been writing large-scale JS applications with SproutCore since 2007, and not once have I been bitten by a bug that would have been caught by static typing.

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

Re: TypeScript: a language for application-scale JavaScript development

#49
All of these compile-to-JS efforts are great, and as much as I love things like CoffeeScript I have to say I definitely worry about language fragmentation.

JavaScript 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.

Re: TypeScript: a language for application-scale JavaScript development

#50

This looks great, but the IDE seems to be one of the key features, so we're going to need something other than Visual Studio. 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/...

Our language service APIs are all open source, so feel free to hack together support for your favorite IDE and let us know! (Check out the code under src\services, and let us know if you have questions.)
Post reply on HN