M Logo
๐Ÿ“ TypeScript from Zero ยท Part 11 of 50

TypeScript Project Setup: npm init, tsconfig.json and tsc Explained

November 6, 2026

Welcome to episode 11 of TypeScript from Zero, a series for complete beginners (no JavaScript needed). Welcome back to TypeScript from zero! Until now we checked single files. Real programs are projects: a folder with a package file, TypeScript installed, and a config file. Today we build one from scratch. Every code block below is the code from the video, ready to copy; run each file to see the output.

1. Folder

We make a folder called shop and go into it. npm init, with dash y, creates the package.json file with default answers. That file describes our project.

bash
$ mkdir shop
bash
$ npm init -y

2. Install

Next we set the project type to module, so we can use import and export later. Then we install TypeScript as a development dependency. Development means: needed while we work, not when the program runs.

bash
$ npm pkg set type=module
bash
$ npm install --save-dev typescript

3. Init

Now tsc with -- init writes a file called tsconfig.json. We open the folder in VS Code, and look inside.

bash
$ npx tsc --init

4. Tour

Every line is a setting for the compiler. Module nodenext is the right choice for Node. Target esnext means we write modern code. And strict true turns on the strictest checks. Always keep strict on. It is the reason TypeScript catches so much.

5. Folders

Two more settings, which we switch on by removing the two slashes. Root dir is where our source code lives. Out dir is where tsc writes the finished JavaScript files.

6. Code

We create a source folder, and a file called index.ts. A small program: a price, a quantity, and the total. Now tsc, without a file name, compiles the whole project. A dist folder appears, and Node runs the JavaScript inside it.

ts
const price: number = 10;
const qty: number = 3;
console.log("Total:", price * qty);
bash
$ npx tsc
bash
$ ls dist
bash
$ node dist/index.js

7. Strict

Now strict mode at work. A function show with a parameter item, and no type. tsc says: parameter item implicitly has an any type. TS7006. It refuses to guess, and that protects us.

ts
function show(item) {
  console.log(item);
}
show("pen");
bash
$ npx tsc

8. Fix

We write colon string after item, and the project compiles again.

bash
$ npx tsc

Recap

Today: a project is a folder with package.json and tsconfig.json. We installed TypeScript with npm, set root dir and out dir, compiled with tsc, and met strict mode. Next episode: reading input from the user.

ยฉ 2026 All Rights Reserved By Mahmudul Alam