Using the TypeScript compiler
In this section, we will learn how to use the TypeScript compiler to type check code and transpile it into JavaScript. First, we will use Visual Studio Code and create a simple TypeScript project containing code we have written in a previous section. We will then use the terminal within Visual Studio Code to interact with the TypeScript compiler.
Open Visual Studio Code in a blank folder of your choice, and carry out the following steps:
- In the EXPLORER panel in Visual Studio Code, create a file called
package.json
containing the following content:{
"name": "tsc-play",
"dependencies": {
"typescript": "^4.6.4"
},
"scripts": {
"build": "tsc src/product.ts"
}
}
The file defines a project name of tsc-play
and sets TypeScript as the only dependency. The file also...