DEV Community

Dan Murphy
Dan Murphy

Posted on

Prepare for Angular with a quick look at TypeScript

When, during the junior phase of the immersive coding program I’m taking, we learned three different frameworks in a week, I questioned why we were learning AngularJS (version 1.7) when there had been so many meaningful updates since.
In addition to the theory that you learn best by seeing how something works before learning how people have made it work easier, it was assumed that we didn’t learn Angular 2.+ because that was when it switched to TypeScript, and they didn’t want to burden us with learning another language while at the same time trying to wrap our heads around the entirely new concept of MVC.
And it was at that very moment that TypeScript became some scary mental impediment to learning one of the most popular frameworks out there.
It wasn’t until I actually had the time to sit and look at what TypeScript is and what it does that I realized that it’s not scary at all. In fact, at its core, it’s just JavaScript with some extras.

What is it?

Developed by Microsoft and released in 2012, TypeScript s a superset of JavaScript that compiles down to JavaScript, making it easy to integrate into existing JavaScript projects. It was designed for the development of large apps, and it’s fully compatible with ES6.

What does it offer?

Among TypeScript’s most notable features is also where it gets its name — static type checking, meaning that variables and functions can optionally be given “types” to indicate the data type that the programmer expects. If, for instance, you declare a variable like so — let myString: string; — and then try to assign it something other than a string, TypeScript will throw an error when compiling down to ES5, but be aware that it won’t actually stop you from assigning the wrong type, so you have to keep a close eye on the console. Type-checking makes it easier to find and prevent bugs, and it will make your code more readable and descriptive.
TypeScript types include familiar JavaScript datatypes, such as string, number, boolean, array, and null, but also any, void, tuple, enum, and generics.
With TypeScript, class-based objects provide true object-oriented programming to JavaScript. In lieu of prototypes, subclasses and inheritance keep functionality in order.
Using TypeScript in your JavaScript projects is as easy as compiling the code down by using the tsc prompt in the command line, and in doing so, you can help ensure that your code is more accurate and more readable.
If you're looking to learn about TypeScript and how it can help your code, there are a ton of resources out there, including this excellent list of tutorials from the folks at Hakr.io

Top comments (0)