Why use TypeScript in developing Angular applications?

Okay! we get that Angular 2+ applications can be written in TypeScript, JavaScript or even Dart as well. But, often times we hear arguments on which language to use and why using TypeScript is preferred.

Why use typescript in developing angular 2 applications

If you are like me and come from a JavaScript background, you might be inclined to write your Angular applications in JavaScript. I was like, why should I bother learning a new language when I have written all my AngularJS 1.x applications in JavaScript. But, trust me, writing your Angular applications in TypeScript makes more sense even if it means you have to learn a new language. I did and you can too.

I give you three reasons:

  1. The first most important reason is that Angular 2 is written using TypeScript and learning TypeScript to write our code will help understand the framework better.
  2. If you already know a programming language like C# or Java then the learning curve is very less. It might be a bit difficult if you are coming from pure vanilla JavaScript background but, don’t worry TypeScript is easy to master.
  3. TypeScript is supported by Google, Microsoft, and Facebook. Google uses TypeScript in their Angular 2 apps. Microsoft uses TypeScript and supports it extensively. Facebook uses TypeScript in their ReactJS framework.

TypeScript is type super-set of JavaScript

TypeScript is type super-set of JavaScript that gets transpiled to plain JavaScript. Some of the advantages of using TypeScript are that you can write classes and use modules. TypeScript also provides strong typing for things like variables and function signatures.

Click here to understand the difference between compiling and transpiling?

typescript-is-super-set-of-javascript

What is strong typing?

You may ask what is strong typing? Well A strongly-typed programming language is one in which each type of data (such as integer, character, decimal, and so forth) is predefined as part of the programming language and all constants or variables defined for a given program must be described with one of the data types.

So, strong typing helps during development time to ensure that our JavaScript, which is a dynamic language by nature, is being written and used as intended. It is important to note, though that using the strong typing is optional and it is actually completely possible to just write plain JavaScript in a TypeScript file.

TypeScript is not difficult to master. With a little effort, you can learn most of its basics and feel comfortable in writing complex applications using TypeScript.

I have also created video tutorials on learning Angular using TypeScript. You can subscribe to my channel here.

Hope I gave you enough motivation to start your Angular journey using TypeScript. I found the following two resources to be helpful in learning TypeScript.

https://basarat.gitbooks.io/typescript/content/docs/getting-started.html

https://users.soe.ucsc.edu/~abadi/Papers/FTS-submitted.pdf

Top