TypeScript Tutorial for Angular 7/8 Devs
In this tutorial, we'll learn about TypeScript. The language of Angular.
Angular is written in TypeScript and officially recommended to be used with TypeScript, so you’ll need to have some knowledge of TypeScript, particularly the object oriented concepts such as classes and decorators which are both frequently used in Angular.
What is TypeScript?
TypeScript provides powerful OOP (Object Oriented Programming) features like:
- interfaces and classes,
- a declarative style,
- static typing and modules.
TypeScript is supported by two big companies in the software world, Microsoft, obviously because it's the creator but also by Google as it was used to develop Angular from v2 up to Angular 8 (The current version). It's also the official and recommended language to build Angular apps.
You can install the TypeScript compiler using npm and then you can call it by running the
tsc source-file.ts command from you terminal. This will generate a
source-file.js file with the same name.
You can control many aspects of the compilation process using a
tsconfig.json configuration file. For example, we can specify the module system to compile to and where to output the compiled file(s).
For large projects, you need to use advanced tools or task runners like Gulp and Grunt or code bundlers like Webpack.
You can use grunt-typescript and gulp-typescript plugins for integrating TypeScript with Gulp and Grunt which will allow you to pass the compiler options from your task runners. For Webpack, you can use the loader to work with TypeScript.
Type definitions are files that end with the
To install them you need to use Typings. It has its own configuration file, which is called
typings.json, where you need to specify paths for type definitions.