Hacker News new | ask | show | jobs
by jolt 4624 days ago
I think typescript is such a good idea. And generics is a great addition.

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.

2 comments

One of the major problems with JavaScript has always been that there are too many options. I feel like TS reduces some, but it still lets people choose between a module pattern (AMD, CommonJS), and the traditional everything-in-the-global-scope way of writing programs.

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

TypeScript doesn't handle dependencies. The <reference> tag is just for the compiler to know where to find the type definitions you are using in a file. For proper dependency handling you still need to use something like RequireJS.