Skip to main content

Beginner-Friendly Topic

Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!

Lesson 8 of 9

`tsconfig.json` - The Basics

`tsconfig.json` controls everything the TypeScript compiler does - what files to include, what JavaScript to emit, and which checks to run. Most developers copy-paste a default and never understand why. Understanding the options means you can tune TypeScript exactly for your project.

11 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

tsconfig - Critical Options Explained

tsconfig - Critical Options Explained
// ── tsconfig.json - production-ready Node.js project ──────────
// {
//   "compilerOptions": {

//     ── What JavaScript to emit ────────────────────────────────
//     "target": "ES2022"
//       Output JS version. ES2022 is safe for Node 16+ and modern browsers.
//       Older targets mean TypeScript transpiles async/await to generators.

//     "module": "commonjs"
//       Module format for Node.js. Use "ESNext" for Vite/browser bundlers.

//     "lib": ["ES2022"]
//       Which built-in APIs are available (Array.at(), structuredClone, etc).
//       Do NOT add "dom" to Node.js projects - separates Node vs browser APIs.

//     ── Type safety ────────────────────────────────────────────
//     "strict": true
//       Enables ALL strict checks in one flag. ALWAYS use this.
//       Equivalent to:
//         strictNullChecks: true          (null/undefined handled separately)
//         noImplicitAny: true             (no implicit any params)
//         strictFunctionTypes: true       (covariant function typing)
//         strictPropertyInitialization    (class props must be initialised)
//         ... and more

//     "noUncheckedIndexedAccess": true    (not in strict, but recommended!)
//       Makes arr[0] return T | undefined, not T.
//       Forces you to handle the "array might be empty" case.

//     "exactOptionalPropertyTypes": true  (advanced - stricter optional props)

//     ── Module resolution ──────────────────────────────────────
//     "moduleResolution": "Node16"
//       How TypeScript finds imported modules. Use Node16 or Bundler
//       for modern projects. Prevents common import resolution confusion.

//     "baseUrl": "./src"
//     "paths": { "@/*": ["./*"] }
//       Path aliases - import from "@/utils/logger" instead of "../../utils/logger"

//     ── Output ─────────────────────────────────────────────────
//     "outDir": "./dist"           Compiled JS output directory
//     "rootDir": "./src"           Source root (mirrors to outDir)
//     "declaration": true          Emit .d.ts type declaration files
//     "sourceMap": true            Source maps for debugging

//     ── Compatibility ──────────────────────────────────────────
//     "esModuleInterop": true      Allows default imports from CommonJS modules
//     "skipLibCheck": true         Skip type-checking in node_modules .d.ts files

//   },
//   "include": ["src/**/*"],
//   "exclude": ["node_modules", "dist", "**/*.test.ts"]
// }

// ── Using a strict base preset (ts-reset, @tsconfig) ─────────
// npm install --save-dev @tsconfig/node20
// tsconfig.json:
// {
//   "extends": "@tsconfig/node20/tsconfig.json",
//   "compilerOptions": {
//     "outDir": "./dist",
//     "rootDir": "./src"
//   }
// }
// Provides opinionated, maintained baseline - no hand-rolling needed.

Common Mistakes

  • `strict: true` is optional - it is not. Always enable it. Without it, `null`, `undefined`, and implicit `any` bypass TypeScript's most valuable checks.
  • Adding `"dom"` to the lib of a Node.js project - this gives Node projects access to `document` and `window` type definitions, masking the real edge runtime difference. Keep `lib: ["ES2022"]` only for Node.
  • Using `skipLibCheck: false` in CI - this makes builds significantly slower by type-checking all of node_modules. Keep `skipLibCheck: true` and instead rely on your own code's type safety.

Tip

Tip

Practice tsconfig Critical Options Explained in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

Visual architecture and concepts for `tsconfig.json` - The Basics

Practice Task

Note

Practice Task - (1) Write a working example of tsconfig Critical Options Explained from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with tsconfig Critical Options Explained is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready typescript code.

Key Takeaways

  • `strict: true` is optional - it is not. Always enable it. Without it, `null`, `undefined`, and implicit `any` bypass TypeScript's most valuable checks.
  • Adding `"dom"` to the lib of a Node.js project - this gives Node projects access to `document` and `window` type definitions, masking the real edge runtime difference. Keep `lib: ["ES2022"]` only for Node.
  • Using `skipLibCheck: false` in CI - this makes builds significantly slower by type-checking all of node_modules. Keep `skipLibCheck: true` and instead rely on your own code's type safety.

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/9 done