TypeScript – is it worth using?

Daniel WylieLanguages, Provider Updates, Resource, Tech Stuff6 Comments


I’ve always had an issue with Javascript transpilers and offshoots that promise to make Javascript better. In this article, I’ll look at both Typescript and Coffeescript.

Coffeescript was the first compiler that appeared on my radar a few years back, and after spending a bit of time playing around with it, I wasn’t convinced.

Yes, it has some niceties that make working in Javascript easier, but unlike Javascript, it’s not something that the majority of developers have dealt with. It’s not a syntax most developers have dealt with. And the learning curve is arguably bigger than just jumping into Javascript.

typescript and coffeescript

Now this isn’t an attack on CoffeeScript at all, it’s an observation on all the various “languages” and abstractions that require some form of “compiler” to turn them into something the browser understands. My guess is that most of these tools aren’t going away seeming as they’re open source – but what if they do? Or what if they introduce massive breaking changes? I know these things can all happen with the “traditional compiled languages” too, but they are generally very stable and maintained by entities with years of experience.

Typescript and Angular 2

With Angular 2 making its’ way out the door recently, I noticed it focuses on TypeScript. Being an Angular 1 fan, I decided to put my reservations aside and have a nosey into the language they’d chosen.

Being dynamically typed is one of Javascript’s best and worst features – with great power comes great responsibility. It’s pretty easy to end up in a mess of Javascript types and functions, especially once you expand beyond a “one person dev team”. TypeScript aims to make it easier to keep track of models and arguments.

Having spent many years in C# land, the idea of having proper types and interfaces intrigues me, mostly as it allows things to be swapped in and out with a known contract, which, in theory at least, saves many hours of testing and rebuilding stuff.

Let’s look at a real simple “Shapes” example, built purely to explore a few different areas of TypeScript. Every shape is based off of a polygon, so we create a IPolygon interface which defines everything we’ll need (for this example)

Now let’s setup a square using our IPolygon interface

You may have noticed I setup a Color object too – this allowed me to explore setting up static variable. They look something like

I then added a “canvas” that we can “draw” to which accepts IPolygon’s and has a draw function, which calls the draw method on each shape.

Coming from C#, it has a familiar vibe to it – it feels almost object orientated. But it doesn’t feel like writing real Javascript. Or more correctly, “old” Javascript. This may not be a bad thing, and after an afternoon of playing around with TypeScript I have grown slightly fond of it and it’s ways.

So to answer my original question – is TypeScript worth using? I’m still not convinced that having another layer over Javascript is worth it, especially with the likes of ES6, but the benefits for bigger teams could far outweigh the downsides given the safety it offers. For smaller projects and new developers though, I think ES6 offers a much more standardised approach to building applications for now.

Next level software intelligence across your entire stack.

6 Comments on “TypeScript – is it worth using?”

  1. Will Murray

    The unanswered question is perhaps, “Does Angular2 bring enough to the table to warrant investigating TypeScript?”
    How would you respond?

  2. John-Daniel Trask

    Hi Will,

    It’s a bit of a chicken & egg situation right? Without framework adoption there is low value in adopting something like TypeScript. Angular was a runaway success in its own right, so Angular2 has momentum behind it to probably make it worth your while to invest in TypeScript.

    Like with all technologies, you are having to make a bet on the future of that technology choice. If I was a gambling man however, I’d think that such a major framework using TypeScript adding significant weight to choosing TypeScript.

    I hope that helps!

  3. William Murray

    That was my thinking, that Angular2 may have the moxie to bring TypeScript from the Microsoft shadows and out to the masses. Thank you for the reply.

  4. Itay

    You’re not addressing one of the major benefits of TypeScript for adoption which is it doesn’t strict you to write JavaScript, as its a superset of it. Also you don’t have to declare for everything. So you can just add it and JS code will work fine side by side to it.

  5. Vinay

    The question is if oo and strict typing is useful to you. If it is, then, type script is useful. Now, I don’t think object oriented ness and strict typing needs selling. If it does require selling, then I would say there is a big missing gap of understanding of software development. As you have more objects and as your functionality grows, you have a proven paradigm to allow your software to become manageable. The only difference is that now that software runs within the browser.

Leave a Reply

Your email address will not be published. Required fields are marked *