Menu

Configuring tsconfig.json

Lesson 3: Configuring tsconfig.json

Which options matter most?

Option Default in TypeScript 6+ What it controls
strict true Enables the strict family of checks, including strictNullChecks and noImplicitAny
target Latest ECMAScript (es2025) Which JavaScript features the output may use
module esnext Output module format
moduleResolution Follows module How imports are found: bundler or nodenext
types [] Which global @types packages load
rootDir Folder containing tsconfig.json Base folder for input files
noUncheckedIndexedAccess false Array and index reads include undefined
exactOptionalPropertyTypes false x?: T cannot be assigned undefined explicitly
noEmit false Check types only, produce no files

Defaults source: TypeScript 6.0 release notes

Example: recommended configurations

App with a bundler (Vite, Next.js, React):

{
  "compilerOptions": {
    "module": "esnext",
    "moduleResolution": "bundler",
    "jsx": "react-jsx",
    "noEmit": true,
    "noUncheckedIndexedAccess": true,
    "verbatimModuleSyntax": true,
    "skipLibCheck": true
  },
  "include": ["src"]
}

Node.js service (run with Node type stripping, checked by tsc):

{
  "compilerOptions": {
    "module": "nodenext",
    "types": ["node"],
    "noEmit": true,
    "erasableSyntaxOnly": true,
    "verbatimModuleSyntax": true,
    "rewriteRelativeImportExtensions": true,
    "noUncheckedIndexedAccess": true
  },
  "include": ["src"]
}

Library published to npm:

{
  "compilerOptions": {
    "module": "nodenext",
    "outDir": "dist",
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    "verbatimModuleSyntax": true
  },
  "include": ["src"]
}

How it works

  • Settings left out use the defaults above, so modern configs can be short.
  • bundler resolution matches how Vite and webpack find files; nodenext matches Node.js rules exactly.
  • skipLibCheck skips checking .d.ts files in node_modules, which speeds up builds and avoids errors in third-party types.
  • Removed in TypeScript 7: target: es5, moduleResolution: node/node10/classic, baseUrl as a lookup root, outFile, and AMD/UMD/SystemJS modules. Move to bundler or nodenext, and put path prefixes in paths.

Common mistakes

Mistake Effect Fix
Copying an old config with moduleResolution: node Errors in TypeScript 7 Use bundler or nodenext
Setting strict: false to silence errors Bugs return Keep strict; fix or gradually migrate (Module 10)
Using paths aliases without configuring the runtime or bundler Imports fail at runtime Configure the same aliases in the bundler, or use #/ subpath imports

Key takeaways

  • Modern defaults are strict and ESM-first; keep configs short and explicit.
  • Choose bundler for front-end apps and nodenext for Node.js and libraries.

Try it: Create the Node.js configuration above for QuickCart, then enable noUncheckedIndexedAccess and fix the errors it reports.


TypeScript Tutorial

J

Jebasta





Get in Touch For Details