TypeScript: Much more than having “closure”

JavaScript or ECMA Script has a community that is always finding ways to make JavaScript “suck less”. Either easier to write, deploy or test. What I have never seen is an attempt to make JavaScript more like “Java”. No language is the magical unicorn perfect for every single situation, only a novice says stupid things like that. Yes, JavaScript is messy, odd and confusing. It’s API is funky and sadly inconsistent from browser to browser. As the content we develop shifts more and more to full blown applications and not mere static content more conventions are needed to ensure that JavaScript protects itself.

TypeScript which was pioneered by Microsoft (yup) since 2012. It has been quite well received by the community. The AngularJS team actually abandoned their development of a similar technology in favor of TypeScript.

Type checking for those who come from Smalltalk and Python they are going to look annoying and cluttered…but that that simply isn’t a priority. Readable code is nice and especially useful to quickly understand…but at the same time it is equally as important if not more important that the developer actually follows the guidelines that they have put into place and not introduce errors that may be hard or even impossible to detect.

Java is verbose, there is no denying it. Java 7 made it possible to omit inferred generic types from a variable’s initialization and that does clean things up a bit. My personal feeling is having greater control trumps speed every time in enterprise applications. For small start-ups that are understaffed and overworked time is of the essence, but that is a different story altogether.

Gradual typing with smart inferred type checking is a very nice balance that should appease those with statically types backgrounds and beyond. TypeScript’s is quite refreshing. The addition of the interface adds an additional dimension to TypeScript. Interfaces in Java always yield a class implementation. In TypeScript you don’t actually need to make a “class” to take advantage of interfaces. They are enormously useful for specifying function parameters.

I will be writing more on TypeScript soon, but start using it now. Ultimately, this is a better way to develop, ending up with a much less error prone code base that requires little to no change beyond “js” to “ts” (and compiling).

Leave a Reply

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