Web Development: TypeScript as OOP version of JavaScript

JavaScript is not classic OOP language

OOP (Object Oriented Programming) is the most popular style of coding for now. OOP programming languages are the most used for now. E.g., C++, Java and C#. These are the most used ones in software development. That’s why the majority of frontend developers have been coding in OOP paradigm. On the other hand, JavaScript dominates on the client side of Web Development. Besides, JavaScript is rising very quickly as server side language by node.js platform. JavaScript is not classic OOP programming language. Actually, there is some kind of OOP based on prototype, but it provides another approaches and patterns. One more point against JavaScript is its dynamically typed nature. These and some other features make JavaScript very outstanding. A lot of developer note that they are hate JavaScript.

 TypeScript for making JavaScript more friendly

There are several attempts to make JavaScript development more friendly and controllable. E.g., CoffeeScript [http://coffeescript.org] is a language that compiles into JavaScript. CoffeeScript code looks like Ruby. Its main goal is providing a minimalistic syntax to make source code smaller and elegant. Another way is TypeScript [http://www.typescriptlang.org] by Microsoft. It makes JavaScript look like regular OOP language with classes and static typing. TypeScript is a language, or rather to say extension to pure JavaScript, because it uses the same syntax as pure JavaScript, but introduces extensions to define types, interfaces, classes, modules, etc. There is a compiler to translate TypeScript code into pure JavaScript to run in browser or by node.js engine. It’s open source both the specification and the implementation hosted on GitHub. Thus, it may be used for any OS and platform. Install it globally into your system as any other npm module:
npm install -g typescript
Then use it to compile source .ts file into pure .js version, like

tsc helloworld.ts

In real application you rather use some engine (e.g., gulp, grunt) to make compilation ts-2-js process as a stage of whole build, or even configure watcher to re-compile fresh version on changes in .ts files. That’s standard approach for any modern Web Development team.

 Benefits of static typing

As I said above, TypeScript provides static typing feature to the JavaScript solution. It checks appropriate types on the translation stage as any other modern OOP compiler. On the other hand, you are free to code in dynamic manner without type checking, if there is a reason at line of optimization or more elegant implementation. Keep in mind, TypeScript is a completely the same as pure JavaScript with all its features, like prototyping, functional programming approaches, etc. Besides, static typing allows TypeScript to be more integrated with IDE’s then pure JavaScript, refactoring is much more easy and effective. GOF and SOLID patterns are applicable, as they are in case of Java and C#. Microsoft made JavaScript world more robust and brings front-end web development to the enterprise level, like its server side. A lot of well-known libraries and frameworks have their versions in the form of TypeScript modules, so you can use their types in your projects.

Read also

Comments are closed.