Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Part 2.1Installing TypeScript

TypeScript is normally installed through npm. The package provides the tsc compiler, which reads .ts files and writes JavaScript files.

The compiler

Terminal
npm install --save-dev typescript
npx tsc --version

Installing it in the project keeps the compiler version recorded with the project. Use npx tsc to run that local version.

Your first file

Create hello.ts and compile it with npx tsc hello.ts. This creates hello.js beside it.

hello.ts
const message: string = "Hello from TypeScript";
console.log(message);

At first, compilation may look unnecessary because the output is nearly identical. The next lessons show what TypeScript can check before that output is created.

Feedback 👍
Comments are sent via email to me.