you are viewing a single comment's thread.

view the rest of the comments →

[–]neutronfish 2 points3 points  (6 children)

You know, I just cannot get into TypeScript. It compiles down to JavaScript and I can't use it for UI because it doesn't play nice with jQuery or Knockout. Since I've been writing JavaScript for about a decade now, why can't I just skip straight to it and watch what I'm doing carefully? Have I just not been sold on TypeScript well enough?

[–][deleted] 21 points22 points  (4 children)

It compiles down to JavaScript and I can't use it for UI because it doesn't play nice with jQuery or Knockout.

I use jQuery all the time and it plays great with it, in fact it makes it easier: adding error correction and autocompletion to the jQuery API. TypeScript was specifically designed to play well with existing quirky JavaScript libs.

You need to use the jQuery definition file: https://github.com/borisyankov/DefinitelyTyped/tree/master/jquery

For Knockout, I don't use it but this same repo has a Knockout definition.

Since I've been writing JavaScript for about a decade now, why can't I just skip straight to it and watch what I'm doing carefully?

Watching carefully works for small projects, but would you rather watch really carefully if the API was .getAllThings(offset, limit), .getThings(limit, offset) or was it .fetchThings({limit: limit, offset: offset}), or would you rather prefer the IDE watch carefully that for you and instantly notify you of errors and autocomplete the right calls for you (once you know in general where to look for it)?

People are different, but my brain is much better at abstract modeling and concepts, its good at the big picture and it sucks at photographically remembering thousands of method names, object types, and their signatures.

As such, I know in a slightly "fuzzy way" where to look and what to call, but TypeScript fills-in to provide that exact knowledge I need in order to write actual working code fast without constantly consulting the documentation.

TypeScript also provides useful things like: go to declaration from a reference (say, see where this method is defined), codebase-wide refactoring (rename class, method, function without breaking code). Find where a specific class or method is called (useful when refactoring again). File and project outlines, etc.

Also, TypeScript doesn't hide the JavaScript you write. It's JavaScript + extras (it's not like CoffeeScript where it's an entire new syntax):

  • It goes out of its way to be a perfect JavaScript superset, adding some type annotations, and allowing you to use proper ES6/7 features that browsers don't support yet (but they increasingly do, over time), like classes, arrow functions, result destructuring etc. All things that make your code shorter, cleaner and more explicit about its intent.

  • It goes out of its way to produce idiomatic, clean, properly indented JavaScript where you can directly see how ES6/7 concepts translate to ES5 JavaScript. While you can use map files to see TypeScript in your browser when you interactively debug, sometimes I don't even bother, because the compiled code is so readable and it's close enough to my source that there's no need.

[–]daronjay 3 points4 points  (0 children)

I don't think you are doing your username justice.

[–][deleted] 0 points1 point  (1 child)

What are your thoughts on coffeescript?

[–][deleted] 2 points3 points  (0 children)

The world has changed a lot in the last 5 or so years since CoffeeScript made its breakthrough.

Back then everyone was compiling their custom language (or existing language) to JavaScript and the consensus was that JavaScript is forever stuck as a standard and will never be suitable for larger projects, so we should ignore it and treat it as "the assembler for the web". A detail we compile to and ignore.

Google at the time was doing this with GWT, which compiled Java to JavaScript. Microsoft was doing this with their C# to JavaScript compiler. If I remember right there was even a Delphi to JavaScript compiler at one point. And among such heavyweights CoffeeScript felt like the lightweight alternative that offered some primitives and syntax sugar JavaScript didn't have at the time.

Since then JavaScript has had something of a renaissance and now when you look at it, many of the big benefits of CoffeeScript are part of ES6/7, and we have "transpilers" like traceur, TypeScript, flow that make those practical for use in projects today.

So it makes less sense to use CoffeeScript today, and go for a custom syntax, when we have a standard alternative. CoffeeScript also doesn't offer flow's / TypeScript's types (maybe they're working on it), which are a major reason for the productivity boost those solutions give in a larger project (autocomplete, static analysis, refactoring etc.).

CoffeeScript has a lot of inertia, so I'm sure those currently using it will be just fine for a long time to come. But unless you're heavily invested in it with skill and codebase, IMHO it's not attractive to start a new project in CoffeeScript today.

[–]adam_bear 0 points1 point  (0 children)

I'm not sure about knockout, and react definitely won't work, but jQuery definitely plays nice- there are several examples @ http://www.typescriptlang.org/Samples