Installing TypeScript & tsconfig.json - Complete Guide 2026

Step-by-step guide to install TypeScript, set up tsconfig.json, and compile your first TypeScript program!

Introduction

Let's install TypeScript and set up our first project!

What You Will Learn

  • Install TypeScript globally and locally
  • tsconfig.json setup
  • Compile TypeScript to JavaScript
  • First TypeScript program

Prerequisites

Step 1: Install TypeScript!

Option A: Globally (Good for CLI use!)

npm install -g typescript
# Check installation
tsc --version

Option B: Locally (Recommended for Projects!)

# Initialize a project
npm init -y
# Install TypeScript as dev dependency
npm install -D typescript

Step 2: Create tsconfig.json!

Configure TypeScript with tsconfig.json!

# Generate basic tsconfig
tsc --init

Recommended tsconfig.json!

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "outDir": "./dist",
    "rootDir": "./src"
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

Key tsconfig Options!

  • strict: Enables all strict checking (RECOMMENDED!)!
  • target: What JS version to compile to!
  • outDir: Where to output compiled JS!
  • rootDir: Where your source TS files are!

Step 3: First TypeScript Program!

  1. Create src/index.ts!
// src/index.ts
const message: string = "Hello TypeScript!";
console.log(message);

function greet(name: string): string {
  return `Hello, ${name}!`;
}
console.log(greet("VSNEXOS"));
  1. Compile it!
tsc

You'll see dist/index.js!

  1. Run it!
node dist/index.js

Step 4: Watch Mode!

Automatically recompile when files change!

tsc --watch

Best Practices

  1. Always use strict mode: Catches more errors!
  2. Install locally per project: Avoid version issues!
  3. Use tsc --init: Generate tsconfig.json!

Summary

TypeScript is installed and configured! You're ready to write TypeScript!

Related Articles

Previous Tutorial

Why TypeScript

Next Tutorial

Let's learn TypeScript fundamentals! → Variables & Type Annotations