Basics of TypeScript - lordoftheflies/angular-essential-training GitHub Wiki
Selecting transcript lines in this section will navigate to timestamp in the video
- The Angular source code is written in TypeScript. TypeScript is a type super set of JavaScript that gets transpired to plain JavaScript. Some of the advantages of using TypeScript is that you can write ES2015 classes and use modules. TypeScript also provides strong typing for things like variables and function signatures. This helps to aid during development time to ensure your 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. You will be using TypeScript as you learn to write code for Angular. There's a very minimal learning curve to get to where you need to be in TypeScript with the main focus being on writing classes, using decorators, and a bit of function parameter typing that you need to be familiar with. There are two benefits of going with TypeScript to write your Angular code. The first is simplicity. By being able to write classes and use decorators you end up writing less code that reads cleaner and is easier to follow. The second is the Angular source code. If you're writing your code in the same fashion as the Angular source code, it will be easy for you to look through the source code as you grow your Angular skills. The ability to reference and learn from the source code as you work on your Angular projects, will increase your productivity as well as your understanding of the framework. Using the same pattern of writing code, in this case TypeScript, will provide you an accelerated benefit in that area. Let's take a quick look at some code for an Angular component and highlight the parts that are TypeScript. At the top of this code, there is an import statement. This is some TypeScript syntax that will handle module loading. The add component block of code is a TypeScript decorator. Below that there is a class definition. The class syntax is actually ES2015 but the export keyword is a TypeScript thing for turning the class into a module. Within the class, there's a constructor function, which is also an ES2015 thing but the parameter it takes in has a colon and then a type behind it that is TypeScript syntax for strong typing a parameter. While these concepts seem complex now, they will make more sense as you progress through the course.