You start a new server side nodejs project, happily writing up stuff in JS, making up objects and members on the fly. All is going well till the day you don’t feel like properly commenting a module. Fast forward 2 weeks in the project, a new developer joins you or somebody changes the method signatures or perhaps you need to make use of the aforementioned module. You are left with no choice but to open up the module source file, read and understand the input/output structure and then proceed with your project.

Typescript, the magic bullet

According to the typescript site,

TypeScript lets you write JavaScript the way you really want to.
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.
Any browser. Any host. Any OS. Open Source.

In simpler terms, typescript adds static type checking to JavaScript. Typescript also brings the familiar OOP concepts of classes, interfaces and generics to the table, all the while compiling (transpiling) into plain old javascript. Due to the availability of type information, typescript makes it possible for IDEs to generate intellisense & autocomplete info. Developer productivity++.

Typescript, the bullet that bites back

While typescript does impart a pretty good structure to your JS project, it is a pain to integrate 3rd party code into your project without the typescript compiler complaining about everything. Typescript’s solution to this problem is .d.ts files which are definitions of what to expect from a 3rd party project. While the TSD github project does have the definition files for most of the widely used libraries, sometimes it can be a pain to use libraries created by others. Take for example, the popular nodejs mongo db driver, mongoose. If your module uses mongoose, good luck to you! Creating a simple class will have you jumping through hoops, extending classes, creating duplicate interface definitions and what not.

My experiences with Typescript

It was mid-way through the development of (still a WIP) that I decided to port the code to Typescript & enjoy some intellisense features in my IDE. Porting the code was a smooth experience till the time I started porting my DB layer, which makes use of mongoose library. It was at this point that I hit a couple of roadblocks w.r.t. the way I wanted to do things & the way Typescript wanted me to write the code. Since the decision to use Typescript was based on the assumption that I will get things done faster & porting mongoose dependant files was taking longer than expected, I decided to revert my changes & go back to plain JS (bye bye intellisense).


I have no doubt that Typescript is an excellent addition to the JS ecosystem & will surely benefit those who have the patience to write & edit definition files for 3rd party libraries. But for now, I am sticking to properly commented, plain JS code.

Typescript: The good, the bad & why I am not using it (for now)
Spread the word...
Share on Facebook2Tweet about this on TwitterShare on Google+0Share on LinkedIn0Pin on Pinterest0Share on Reddit0Share on Tumblr0Email this to someone