Wednesday, January 2, 2013

Generating Google Closure JavaScript from TypeScript

Over a year ago, I created a prototype for generating Google Closure JavaScript from CoffeeScript. Today, I am releasing a new, equivalent prototype that uses TypeScript as the source language.

<shamelessplug>I will be speaking at mloc.js next month in Budapest, Hungary, which is a conference on scaling JavaScript development. There, I will discuss various tools to help keep large codebases in check, so if you are interested in hearing more about this work, come join me in eastern Europe in February!</shamelessplug>

I have been interested in the challenge of Web programming in the large for quite some time. I believe that Google Closure is currently still the best option for large-scale JavaScript/Web development, but that it will ultimately be replaced by something that is less verbose. Although Dart shows considerable promise, I am still dismayed by the size of the JavaScript that it generates. By comparision, if TypeScript can be directly translated to JavaScript that can be compiled using the advanced mode of the Closure Compiler, then we can have all the benefits of optimized JavaScript from Closure without the verbosity. What's more, because TypeScript is a superset of JavaScript, I believe that its syntax extensions have a chance of making it into the ECMAScript standard at some point, whereas the chances of Dart being supported natively in all major browsers is pretty low.

In terms of hacking on TypeScript itself, getting started with the codebase was a pain because I develop on Linux, and presumably TypeScript's developers do not. Apparently Microsoft does not care that cloning a CodePlex repository using Git on Linux does not work. Therefore, in order to get the TypeScript source code, I had to switch to a Mac, clone the repo there, and then import it into GitHub so I could clone it from my Linux box.

Once I got the code on my machine, the next step was figuring out how to build it. TypeScript includes a Makefile, but it contains batch commands rather than Bash commands, so of course those did not work on Linux, either. Modifying the Makefile was a bit of work, and unfortunately will likely be a pain to reconcile with future upstream changes. It would be extremely helpful if Microsoft switched to a cross-platform build tool (or maintained two versions of the Makefile themselves).

Once I was able to build, I wanted to start hacking and exploring the TypeScript codebase. I suspected that reading the .ts files as plaintext without any syntax highlighting would be painful, so I Googled to see if there were any good alternatives to Visual Studio with TypeScript support that would run on Linux. Fortunately, JetBrains recently released a beta of PhpStorm and WebStorm 6.0 that includes support for TypeScript, so I decided to give it a try. Given that both TypeScript and support for it in WebStorm are very new, I am quite impressed with how well it works today. Syntax highlighting and ctrl+clicking to definitions work as expected, though PhpStorm reports many false positives in terms of TypeScript errors. I am optimistic that this will get better over time.

Now that I have all of the setup out of the way, the TypeScript codebase is pretty nice to work with. The source code does not contain much in the way of comments, but the code is well-structured and the class and variable names are well-chosen, so it is not too hard to find your way. I would certainly like to upstream some of my changes and contribute other fixes to TypeScript, though if that Git bug on CodePlex doesn't get fixed, it is unlikely that I will become an active contributor.

Want to learn more about Closure? Pick up a copy of my book, Closure: The Definitive Guide (O'Reilly), and learn how to build sophisticated web applications like Gmail and Google Maps!

44 comments:

  1. Michael,

    With regard to the Linux/CodePlex Git issue. We have seen the before in a few instances. Try updating the version of Git.

    In the past this as been an issue with an older version of Git.

    Let me know if this does not work for you.

    Thanks,
    Mark - CodePlex

    ReplyDelete
  2. I have not been this excited since like forever. This would be so huge and so cool I cannot wait. Unfortunately I would assume it will not be that stable in the beginning, however the benefits are evident. I have tried typescript in a project and because I have read the mailing lists I see that most people face large difficulties with types and sub-typing and stuff, but it comes so naturally when you have already been using closure compiler in advanced mode I could say I don't think I could ever again write untyped code. I really really prefer the type annotations as they are in typescript, so much easier to write... so please please please make this work:)

    Thanks

    ReplyDelete
  3. You might want to checkout the "develop" branch of the TypeScript source which comes with a jakefile. That makes compiling TypeScript way easier on non Windows systems.

    Best,

    Julian

    ReplyDelete
  4. I think it's a great project. Combination of TypeScript and Google Closure can be very powerfull and very nice to work with. For me, it can be best option now in the JavaScript world.

    ReplyDelete
  5. Good job, I look forward to giving this a go.

    It would be nice to have a reverse version of this tool available, so that existing Closure codebases (including the Closure Library) could be converted to TypeScript.

    ReplyDelete
  6. Hi Michael,

    Is this an experimental project and how do you handle and merge new versions of the typescript?

    Thanks

    ReplyDelete
  7. I'm using closure at the moment, and Typescript+closure looks like a big productivity gain.

    A couple of notes about Dart. The javascript cross compiler, dart2js, has recently landed some changes to type inference that look like they are really paying off. For the two linked benchmarks, cross compiled code is running at 0.86x, and 0.74x, of the handcoded javascript versions. See http://www.dartlang.org/performance/. The type inference is likely also having a large impact on the generated javascript code size. I haven't seen any numbers yet. Perhaps file a bug report to get the Dart team to add a code size chart of the benchmarks on their performance page.

    It is now also possible to do deferred code loading, which can help with start up time. See: http://api.dartlang.org/docs/releases/latest/dart_async/DeferredLibrary.html

    As soon as I can drop IE8 support in my apps, I will switch to Dart.

    However, I imagine for some apps, I will want to hand code the performance sensitive parts in javascript using closure. (Maybe javascript really is becoming the assembly langauge of the web?)

    ReplyDelete
  8. Follow other people in return: If you consider the fact that social media can only be successful if you have flourishing relationships with other people, buy google likes

    ReplyDelete
  9. I can not stop myself to read this post! Thanks. Kanhasoft is the mobile and web solution developer in India and USA. We are developing a complete enterprise solution to boost the business. Visit our site to know more.

    ReplyDelete
  10. Thank you for a useful interesting article, I completely agree with you,
    I was also recommended a resource with instagram likes where you can buy them.

    ReplyDelete
  11. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here keep up the good work get free ig likes

    ReplyDelete
  12. Stay at Home, Stay Safe! I am experienced social media marketing expert providing ROI service from last 5+ years certified by inbound marketing, facebook advertising, instagram marketign expert, and more. Now let's grow your business or profile visibility in organically. Or You can boost your business, sell, profile visibility or traffic or followers by getting my 100% safe and real service in cheap prie. so lets get connect if you nedd to buy Facebook page likes usa or post likes or anyting ealse, or instant instagram followers or only usa targeted country likes & folowers.

    ReplyDelete
  13. Vi på Pool Sweden AB levererar exklusiva pooler, pooltak, spabad och swimspa till livsnjutare runt om i landet. Våra produkter passar dig som har höga krav på kvalitet och design och vill kunna njuta av din pool i många år framöver. Ofta levererar vi våra pooler hundra procent klara för bad, där vi sköter grävning, installation och vattenfyllning. Och du kan fokusera på många sköna badstunder. for more details here : https://poolsweden.se

    ReplyDelete
  14. For all time of business and for all type of businesses, growing online is essential and for that you can get Real instagram followers for free who can give you a good push towards success.

    ReplyDelete
  15. For all time of business and for all type of businesses, growing online is essential and for that you can get Free Instagram Followers who can give you a good push towards success.
    https://instagix.com/

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. I like to gamble on csgo case opening sites and I play on a lot of them. If you are interested in earning extra money check out this list of the best csgo cases in 2021 with promo codes and welcome bonuses.

    ReplyDelete
  18. You make a lot of good points. Personally when I am looking for free csgo skins, I use the top csgo betting sites in 2021 that have free coins with referral codes.

    ReplyDelete
  19. They have a great Instagram promotion for blogs like yours to be seen. They also let you buy targeted views for Tikok and YouTube !

    ReplyDelete
  20. There is a great place to get a YouTube Promotion but they also let you buy instagram followers and more !

    ReplyDelete
  21. This comment has been removed by the author.

    ReplyDelete
  22. Good topic! I really love how it is simple on my eyes and the data are well written. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which must do the trick! Have a nice day! Seglakaribien.se

    ReplyDelete
  23. Your having a show, parts of this come away as your body gets ready to go into labour, some people hyra-segelbat.se

    ReplyDelete
  24. It is a good article and I agree with what is said BUT there are to stop him. I just went with him, praised and went back to the ramp Seglakroatien.se

    ReplyDelete
  25. Wonderful Article.Enjoyed reading the article above Köpsegelbåt.se

    ReplyDelete
  26. A debt of gratitude is in order for setting aside an ideal opportunity to talk about this, I feel unequivocally about it and affection adapting more on this subject Seglaitalien.se

    ReplyDelete
  27. This is very informatics, fresh and clear. I feel that everything has been portrayed in orderly way with the goal that peruser could get most extreme data and realize numerous things Greklandsegling.se

    ReplyDelete
  28. I'm extremely pleased to uncover this website. I need to to
    thank you for one time,just for this wonderful read!!
    Regards
    Pasir Ris 8 Condo

    ReplyDelete



  29. Nice post. I used to be checking constantly this blog and I am impressed! Extremely useful info particularly the ultimate section 🙂 I take care of such information a lot. I was seeking this certain information for a long time. Thank you and best of luck.
    Azadi ka Amrit Mahotsav essay , The Beautiful Sky Book review

    ReplyDelete
  30. You may want to get fit not mater in which life stage you are, but the problem is we don't find enough time to do effort. I was also the same but then I read the Kathryn Dennis Weight Loss journey and some other transformations, such as Jenny Doan Weight Loss, Retta Weight Loss, Miranda May Weight Loss and Action Bronson Weight Loss Journey.

    ReplyDelete
  31. Hey! I found this URL from one of my Facebook group and believe me you have provided awesome content, which
    will help many of us.
    You can also check my link below:
    Best networking marketing company in India
    Kids Dentistry in Chennai

    ReplyDelete
  32. There is a simple way to play stake in us.It works for me. Thanks for sharing.

    ReplyDelete
  33. There is a simple way to play بازی انفجار.It works for me. Thanks for sharing <3

    ReplyDelete
  34. A superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place. Visit https://knoxvilleawnings.com for more details.

    ReplyDelete
  35. This comment has been removed by the author.

    ReplyDelete
  36. Thanks for sharing...very informative.

    Are you planning to launch an on demand photographer app ? Before make any decision read our blog and hire the best app developers at The App Ideas.

    ReplyDelete
  37. Hi there! I just want to offer you a huge thumbs up for the great information you have here on this post. I’ll be coming back to your website for more soon.장성군출장샵
    신안군출장샵
    완주군출장샵
    진안군출장샵
    무주군출장샵
    장수군출장샵

    ReplyDelete
  38. This comment has been removed by the author.

    ReplyDelete
  39. Tennis is a sport that often requires athletes to make quick decisions. In particular, the game of tennis can be taxing on the wrists and forearms because of the movement required to hit a ball over a net. Check out what is Icing in Tennis, Walkover in Tennis, and Is Tennis a Team Sport

    ReplyDelete
  40. Nice post. Thanks for sharing with us Such amazing information

    ReplyDelete
  41. Data annotation is an indispensable technology in industries such as robotics and automotive, especially in solutions designed for autonomous driving. However, it can also be useful in other, not so obvious areas, in which ones? - read this special info and now bring new technologies to your business that will change the course of its development!

    ReplyDelete
  42. You most likely need to hire a programmer online as JS is notable and broadly utilized for intuitive web and portable JavaScript application improvement and there is various organizations anxious to employ committed JavaScript engineers to chip away at their web administrations.

    ReplyDelete