TypeScript Overview and Benefits
This guide provides an overview of the TypeScript programming language along with listing some of the key benefits associated with TypeScript.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

Welcome to this course on typescript and the typescript programming language. If you've never worked with typescript I think you're going to be in for a treat. It takes in some of the best components of other languages such as a java or C++ and it merges that in with more modern scripting languages like JavaScript or even Ruby, and it takes some of the things that make those languages great and helped to kind of enforce some rules to make them a little bit less buggy or more prone or less prone to errors.

Who created typescript?

Typescript was actually created by Microsoft which is a little bit surprising because it's pretty rare that I like something that Microsoft puts out there especially on the developer side. I'm not a big fan of the .Net framework or a lot of the things that they've put out there. However with typescript they absolutely hit it out of the park. In fact they made typescript so good and so practical to use that angular 2 is actually built and written in the typescript programming language. You probably wouldn't be working with typescript if that weren’t the case. So right now there are tons of developers who are learning how to use typescript because if you want to develop in the angular 2 framework, typescript is almost a prerequisite for that. However even if it wasn't, typescript actually has a lot of benefits that's good for developers to learn whether they're looking to build all types of applications or also if they're wanting to learn how to implement best practices into those apps.

Attributes

Let's talk about a few attributes typescript has. First thing to know and you may have guessed from the name is that. Typescript. Is very serious about its types and it is statically typed. This is different than something or a language that is dynamically typed. So if you're used to working with Ruby, JavaScript, or Python those are all dynamically typed languages, which means that you can do something like this. You could declare a string.

str = “my string”

Because the compiler in this case is ruby it is is going to recognize that this is a string data type and it's just going to act accordingly. So in the background what Ruby is actually doing is it's taking the string value and it's saying hey this is actually of the string data type so we need to treat it like that. You don't have to declare it but the parser takes what you try to do, and it assumes the best. That's fine and it works in many different cases. However there are times where you'll run into confusing bugs based on dynamically type languages like this. Take for example, and I'm going to use a little bit of a visual here. I'm going to create a box and I'm going to put an S in it meaning that this is a string. Also over here in a circle I'm going to put an I which stands for integer. Now one thing that happens a lot especially when you're working with APIs because usually they're json, they're going to be sending string values in there. However what if you have an algorithm that expects an integer. You actually have to convert that string value into an integer. And if you forget to do that you're going to run into problems. So say that we have an API, and we try to pipe a string into something that takes an integer.

large

You can run into a number of different type errors and I use this visual because it's like you're trying to fit a square peg inside of a round hole. That's something that happens a lot with dynamically typed languages. And it's part of the reason why some people don't like using them, specifically for cases like this.
However what typescript does is it actually takes a lot of the benefits of being able to use dynamically typed languages and in fact it makes types optional but it takes these benefits and then it combines that by giving you the ability to declare your types, so this doesn't happen. You're always going to be able to know, and you should be able if you build the program properly what's going to happen. So if you know a string is going to be coming in from the API then you should have a method or something that is able to process that so that you don't run into errors.

So that's a little bit of a background on typescript in terms of who created it, Some of the benefits to using it, and one of them being if you want to build angular 2 apps it's very important to know. In addition to it being typed what typescript also does is it gives JavaScript a much more object-oriented nature. In JavaScript if you've never really used it before doesn’t have a true concept of classes or inheritance. You have to do some kind of jerry rigging to do things like creating prototypes and then being able to clone those and to do a lot of weird things that aren't very intuitive. To someone who's used to object oriented programming, what typescript does is it actually creates a wrapper around it and around the JavaScript language, which allows you to use a much more object oriented nature, it has things like classes, it has the different interfaces, and it has ways of being able to take some of the really nice things about object oriented programming and then apply them with modern development and have some more data quality checks around how you build your applications.

I'm really excited about this section. It's going to be a great prerequisite course for learning how to build real world rails and angular applications. So let's now take a deeper dive into how to get typescript up and running on your systems. And then we're going to go into how to build typescript programs.

Resources