Skip to content

The tsc compiler

Course: Typescript - chapter 3

Let’s bootstrap a simple Typescript Node.js application locally on our machines

Terminal window
npm install -g typescript

Step 2 - Initialize an empty Node.js project with typescript

Section titled “Step 2 - Initialize an empty Node.js project with typescript”
Terminal window
mkdir node-app
cd node-app
npm init -y
npx tsc --init

These commands should initialize two files in your project

const x: number = 1;
console.log(x);
Terminal window
tsc -b

Step 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

Make sure you convert the const to let

let x: number = 1;
x = "harkirat"
console.log(x);
tsc -b

Notice 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