Getting Started with TypeScript

In this chapter, we will look at TypeScript and see how to use TypeScript in a new project or an existing JavaScript project. We will see how to adapt the environment of your current build setup. TypeScript can be supported by a variety of build tools, such as Grunt, Gulp, webpack, or simply by using the command-line interface (CLI). We also look at the best options, among all the ones available, for getting started with TypeScript.

Before configuring any build tool, it's important to understand that all of them use the same TypeScript compiler, often called a transpiler. The TypeScript compiler is available by using npm:

npm install -g typescript

Npm might not be installed by default on your computer. If that is the case, the previous instruction will fail. It means you need to install Node.js. You can install Node.js by going to the official website, https://nodejs.org/.

At any time, you can verify that you have Node.js, npm, and TypeScript installed by using the following command:

node -v
npm -v
tsc -v

TSC is the executable for the TypeScript compiler. This is the one that is used by all build tools. Grunt, Gulp, and webpack use TSC via their own plugin infrastructures that map TSC features to their platform. Note that recent TSC features might take a few weeks before reaching these platforms. This might explain the differences in compiler options when using these three build systems. In contrast, using a TSC CLI ensures that you are using TypeScript directly.

This chapter covers the following:

  • Grunt
  • Gulp
  • Webpack 
  • NMP/CLI 
  • TypeScript compiler
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.188.95