Learning TypeScript
Following the release of Angular 2 Beta, like many other front-end developers currently using AngularJS, I became very interested in what the transition from Angular 1 to 2 would be and how it might impact what I am working on right now.
Right away I had many questions! I just wrapped my head around AngularJS and now I have to switch to Angular 2?! How is it better? Will I be able to easily convert what I’ve already written? When will it get out of Beta? Who is really going to use it? How much support will I have if I attempt to start my move to Angular 2 now?
Why Learn TypeScript?
These questions inspired me to do extensive research. Like I said before, many developers are excited about Angular 2, so there are many articles and other peoples thoughts to read through and compare. Many articles later, I realized I really needed to begin by learning TypeScript, since Angular 2 itself is written in it. So I looked into the basics, enough to build an application and start playing with the code.
I went to a great talk last week that I wish I had seen prior to my research! Dirk Weibel, here in Richmond, Virginia, gave a great overview of this JavaScript superset and then spent a good amount of time walking us through some code examples of its use.
Dirk started the talk by saying that TypeScript is really well suited for large development. Using the technologies available today, “hands in the code” really becomes an issue sometimes, especially in a large project or on a large team. Even when the amount of developers isn’t an issue, we must still maintain clean code.
Starting to Like the Idea of Using TypeScript
Optional static typing is available. What this means is you, as the developer, have the ability to set the “type” of data your variable is going to hold and that type is then verified on compilation. This allows many bugs to be caught early and is a great start for program verification.
Using static typing, code becomes easier to maintain; you can quickly integrate new developers into your team and bring them up-to-speed with the code; it’s also much less likely for a team member to misuse code. The power of TypeScript comes from the ability to use static typing.
So why is it better than just using JavaScript? Yes, you have this new, fancy way of pre-debugging your code with static typing, but are there any other reasons we should be using it? There are many great reasons, but here are a few from Dirk’s talk and a few I came across:
- It supports ES6, as well as compiles to older ECMAScript standards if needed.
- JavaScript is valid TypeScript! TypeScript is actually compiled into JavaScript. Migrating back to JavaScript then becomes very simple. TypeScript will then continue using the advancements of JavaScript while improving on any flaws.
- Excellent IDE support such as Visual Studio, Sublime and IntelliJ, among others. The development experience is greatly improved because the IDE knows what is allowed and what is not. Because of this support, compilation errors can be displayed within the IDE. This will reduce the amount of time spent getting your code to work!
- It is Open Source and is supported by Microsoft. TypeScript has seen great activity.
- Angular 2, as well as some other great projects such as RxJs, is coded using TypeScript.
So using TypeScript is a good idea. I’ll have to dive more into Angular 2 to really understand all the questions I still have. I’ll plan to cover answers to those questions in future posts, coming soon!
TypeScript Resources:
Main TypeScript Site – http://www.typescriptlang.org/
Basic TypeScript Quick Start Guide – http://www.typescriptlang.org/docs/tutorial.html
Main TypeScript Github – https://github.com/Microsoft/TypeScript
Great TypeScript Resources Github – https://github.com/dzharii/awesome-typescript
AngularJS Resources:
Main Angular2 Site – https://angular.io/
Basic Angular2 Quick Start Guide – https://angular.io/docs/ts/latest/quickstart.html
Main Angular2 Github – https://github.com/angular/angular
Fun Sites Built to Angular2 – http://angularexpo.com/