12. Using Next-Generation JavaScript
Activity 12.01: Creating a Project to Recognize and Compile TypeScript Files
Solution:
- The first step is to create a new project directory, then
cd
into it, and initialize it for npm:mkdir my_app cd my_app npm init
- Next, install Parcel as a global library:
npm install -g parcel
- Now, you will need to install TypeScript, which you can also save as a global library:
npm install -g typescript
- To generate the configuration for TypeScript, you simply need to call the TypeScript CLI tool,
tsc
, and pass it the--init
flag:tsc --init
If all went well, you should be presented with a message such as the following:
message TS6071: Successfully created a tsconfig.json file.
You should also find a new
tsconfig.json
file in the root of your project folder. - Next, create a directory called
src
and place anindex.ts
file within it. Add the following code as the file's content:const message:string = "Hello, World!"; console...