Hands-On Full Stack Web Development with Angular 6 and Laravel 5
上QQ阅读APP看书,第一时间看更新

Installing TypeScript

It's pretty simple to install and get started with TypeScript. It is necessary to have Node.js and Node Package Manager (NPM) installed on your machine.

If you don't have them yet, go to https://nodejs.org/en/download/ and follow the step-by-step installation instructions for your platform.

Let's install TypeScript, as follows:

  1. Open your Terminal and type the following command to install the TypeScript compiler:
npm install -g typescript

Note that the -g flag means to install the compiler on your machine globally.

  1. Let's check the available TypeScript commands. Type the following command in the Terminal:
tsc --help

The preceding command will provide a lot of information about the TypeScript compiler; we will see a simple example of how we can transpile a TypeScript file to a JavaScript file.

Examples:

 tsc hello.ts
 tsc --outFile file.js file.ts

Descriptions of the preceding lines are as follows:

  • The tsc command compiles the hello.ts file.
  • Tell the compiler to create an output file, named hello.js