The tsc compiler
Course: Typescript - chapter 3
Let’s bootstrap a simple Typescript Node.js application locally on our machines
Step 1 - Install tsc/typescript globally
Section titled “Step 1 - Install tsc/typescript globally”npm install -g typescriptStep 2 - Initialize an empty Node.js project with typescript
Section titled “Step 2 - Initialize an empty Node.js project with typescript”mkdir node-appcd node-appnpm init -ynpx tsc --initThese commands should initialize two files in your project

Step 3 - Create a a.ts file
Section titled “Step 3 - Create a a.ts file”const x: number = 1;console.log(x);Step 4 - Compile the ts file to js file
Section titled “Step 4 - Compile the ts file to js file”tsc -bStep 5 - Explore the newly generated index.js file
Section titled “Step 5 - Explore the newly generated index.js file”
Notice how there is no typescript code in the javascript file. It’s a plain old js file with no types
Step 7 - Delete a.js
Section titled “Step 7 - Delete a.js”Step 6 - Try assigning x to a string
Section titled “Step 6 - Try assigning x to a string”Make sure you convert the const to let
let x: number = 1;x = "harkirat"console.log(x);Step 7 - Try compiling the code again
Section titled “Step 7 - Try compiling the code again”tsc -bNotice all the errors you see in the console. This tells you there are type errors in your codebase.
Also notice that no index.js is created anymore

This is the high level benefit of typescript. It lets you catch type errors at compile time