LearnFrenzy
Sign in Take a free test

Getting Started with TypeScript · Lesson 2 of 17

Install TypeScript, tsconfig and Strict Mode

4 min read Updated Nov 8, 2026 Saurabh Samir

This lesson sets up a TypeScript project the way professional teams do: TypeScript installed per project, a tsconfig.json with strict mode on, and a quick way to run files while you learn. It takes about five minutes.

In this lesson

  • Installing TypeScript with npm
  • Compiling with tsc
  • tsconfig.json and the options that matter
  • Running TypeScript quickly while learning

Install

You need Node.js (LTS). Then, in a new folder:

npm init -y
npm install --save-dev typescript @types/node   # per project, so everyone uses the same version
npx tsc --version
npx tsc --init                                  # creates tsconfig.json

Install TypeScript per project rather than globally, so every developer and the CI server compile with the same version.

Your first compile

// src/hello.ts
function greet(name: string, year: number = 2026): string {
  return `Hello, ${name}! Welcome to TypeScript in ${year}.`;
}
console.log(greet("Asha"));
console.log(greet("Ravi", 2027));

Output

Hello, Asha! Welcome to TypeScript in 2026.
Hello, Ravi! Welcome to TypeScript in 2027.
npx tsc              # type-check and compile everything in tsconfig.json → dist/
node dist/hello.js
npx tsc --noEmit     # type-check only (common in CI)
npx tsc --watch      # recompile on every save

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "rootDir": "src",
    "outDir": "dist",
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "sourceMap": true
  },
  "include": ["src"]
}
OptionWhat it does
targetwhich JavaScript version to emit (ES2022 suits current Node and browsers)
module / moduleResolutionmodule system; NodeNext for Node, Bundler for Vite/Next.js apps
rootDir / outDirwhere sources are and where JavaScript goes
strictturns on all the strict checks – always use it
noUncheckedIndexedAccessarr[i] may be undefined – catches out-of-range bugs
skipLibCheckdon't type-check library .d.ts files (faster builds)
sourceMapdebug the .ts source in VS Code and browsers

What strict mode catches

function shout(message) {                 // implicit any
  return message.toUpperCase();
}
function firstName(names: string[]): string {
  const found = names.find((n) => n.startsWith("A"));
  return found.toUpperCase();             // found might be undefined
}
console.log(shout("hi"), firstName(["Asha"]));

Type errors

main.ts(1,16): error TS7006: Parameter 'message' implicitly has an 'any' type.
main.ts(6,10): error TS18048: 'found' is possibly 'undefined'.

strict includes noImplicitAny (every value must have a known type) and strictNullChecks (null and undefined must be handled). Without them TypeScript misses the bugs that matter most. Start every new project strict; turning it on later in a big codebase is painful.

Running TypeScript while learning

OptionCommandType-checks?
Compile then runnpx tsc && node dist/hello.jsyes
tsx (fast runner)npx tsx src/hello.tsno – run tsc --noEmit separately
Node.js type strippingnode src/hello.ts (Node 23.6+ / 24)no – it just removes types
FrameworksVite, Next.js, Angular CLIbuilt in (type-check in the editor and CI)

Running isn't checking

Fast runners like tsx and Node's type stripping skip type checking – code with type errors still runs. Keep your editor's TypeScript errors visible and run tsc --noEmit in CI so errors can't slip in.

Every example in this course was checked with tsc in strict mode (plus noUnusedLocals and friends) and then run with Node.

Practice

Try it yourself

  1. Write a typed function gst(amount: number, rate = 0.18) that returns the amount with tax, rounded to 2 decimals.

    Show solution
    function gst(amount: number, rate = 0.18): number {
      return Math.round(amount * (1 + rate) * 100) / 100;
    }
    console.log(gst(999), gst(250, 0.05));

    Output

    1178.82 262.5

Quick check

Which command type-checks without writing files?

npx tsc --noEmit.

What does "strict": true enable?

All strict checks, including noImplicitAny and strictNullChecks.

Does npx tsx file.ts check types?

No – it only strips types and runs; use tsc for checking.

Summary

  • Install TypeScript per project; compile with tsc, check with tsc --noEmit.
  • tsconfig.json controls the output; always enable strict.
  • Use tsx or Node type stripping to run quickly, but keep type checking in the editor and CI.

Finished this lesson?

Mark it complete to track your progress, then carry on with the next lesson.

Next lesson

Popular