Powered by Blogger.

TypeScript–Surprisingly Simple, Extraordinarily Powerful– Part 1


Introduction on what TypeScript is and why should we look at it

JavaScript(JS) can be messy, until and unless we are only using JavaScript for bare minimum purpose. But, that’s not possible in today’s world, there are hardly any applications which use JavaScript just for hiding/unhiding (if this is a word) elements or showing alerts. With the advent of sooooo many client-side JS frameworks like JQuery, Knockout, Bootstrap, and hottest them of all Angular, we are writing more and more code on client-side, entire applications are built now with just JS code.

Now, JS is a wonderful language, it's one language which can be used to achieve everything on client-side (nodeJs is enabling JS on the server-side as well), it's very dynamic take an e.g. of the datatype, there are no ints/floats or doubles. Everything is a “var”, var can hold any objects, types are determined on the fly. This provides lots of flexibility and there is a thought that every language should be similar to JS in terms of the type definition. In my opinion, JS should be somewhat like C# and JAVA which can help us write and check proper types for each variable, make sure the relationships are determined at compile time itself. Without these features medium to large projects become un-maintainable especially the JS part, code becomes messy and difficult to reuse. Now, it's not that every project will have these issues, if you have developers who have vast experience in writing JS code, know JS design patterns then you may not face these issues but, let's be honest these folks don’t around easily and cheap.

As has been said by the “John Papa” difference can be between “Spaghetti vs Ravioli” code, and TypeScripts is one such framework to achieve that.

TypeScript(TS) provides compile-time type checking, we can create variables of type int and if we assign a string to it, TS will let us know. We can define classes (coming in ECMA 6) and use class structure to keep our code maintainable. TS is also very suitable for folks coming from a server-side background like C# and JAVA because it provides us with similar concepts for writing JS code.

The important thing of note about TS is that it DOES NOT add anything on top of JS, it's just an alternate which compiles in JS.

No comments