Lesson 2 of 8
tsconfig Deep Dive - All Critical Options
A well-understood `tsconfig.json` is the difference between TypeScript frustrating you and TypeScript helping you. This covers every critical compiler option - target, module resolution, strict flags beyond the `strict` umbrella, path aliases, and multi-target configs for monorepos.
tsconfig - Production Configuration Reference
// ── tsconfig.base.json - shared across Node + React sub-projects ──
// {
// "compilerOptions": {
//
// ── Output format ────────────────────────────────────────────
// "target": "ES2022"
// JavaScript output version. ES2022 = async/await native,
// structuredClone, Array.at(), Object.hasOwn() - safe for
// Node 18+ and modern browsers (with bundler).
//
// "module": "NodeNext"
// Module format. NodeNext supports both CommonJS and ESM.
// For Vite/browser: "ESNext". For older Node: "Commonjs".
//
// "moduleResolution": "NodeNext"
// How TS resolves imports. NodeNext = package.json exports map,
// .mts/.cjs extensions. Bundler = respects bundler resolution.
//
// ── Strict checks - strict: true PLUS extras ─────────────────
// "strict": true // enables 8 strict checks
// "noUncheckedIndexedAccess": true // arr[0] is T | undefined
// "exactOptionalPropertyTypes": true // field?: T ≠ field: T | undefined
// "noImplicitOverride": true // override keyword required in subclasses
// "noPropertyAccessFromIndexSignature": true // obj.unknown disallowed
// "noFallthroughCasesInSwitch": true // switch cases must break/return/throw
//
// ── Module resolution extras ──────────────────────────────────
// "baseUrl": "./src"
// "paths": {
// "@/*": ["*"], // @/utils/log → src/utils/log
// "@types/*": ["types/*"], // @types/domain → src/types/domain
// "@services/*": ["services/*"]
// }
//
// ── Edge runtime separation ────────────────────────────────────
// Node project: "lib": ["ES2022"] // NO dom lib
// Browser project: "lib": ["ES2022", "DOM", "DOM.Iterable"]
// // Keep these SEPARATE. Do not mix dom + node libs.
//
// "verbatimModuleSyntax": true // enforces import type for type imports
// "isolatedModules": true // required for esbuild/Babel compat
//
// ── Output ──────────────────────────────────────────────────
// "outDir": "./dist"
// "rootDir": "./src"
// "declaration": true // emit .d.ts type files
// "declarationMap": true // source maps for .d.ts files
// "sourceMap": true // source maps for .js files
// "removeComments": false // keep comments in output
// "incremental": true // use .tsbuildinfo for faster rebuilds
//
// ── Compatibility ──────────────────────────────────────────
// "esModuleInterop": true
// "allowSyntheticDefaultImports": true
// "skipLibCheck": true // don't type-check node_modules
//
// }
// }
// ── tsconfig.node.json - extends base, Node.js specific ────────
// { "extends": "./tsconfig.base.json",
// "compilerOptions": {
// "module": "NodeNext", "moduleResolution": "NodeNext",
// "lib": ["ES2022"], "outDir": "./dist/server"
// }
// }
// ── tsconfig.browser.json - extends base, React/Vite specific ─
// { "extends": "./tsconfig.base.json",
// "compilerOptions": {
// "module": "ESNext", "moduleResolution": "Bundler",
// "lib": ["ES2022", "DOM", "DOM.Iterable"],
// "jsx": "react-jsx", "outDir": "./dist/client"
// }
// }
// ── Preset - @tsconfig/strictest (recommended) ────────────────
// npm install --save-dev @tsconfig/strictest
// { "extends": "@tsconfig/strictest/tsconfig.json",
// "compilerOptions": { "outDir": "./dist", "rootDir": "./src" }
// }
// Maintained by the TS team - enables every recommended check.Common Mistakes
- Using `moduleResolution: "node"` (legacy) - old Node resolution doesn't understand package.json `exports` map. Use `NodeNext` for Node projects, `Bundler` for Vite/webpack projects.
- Not separating browser and Node tsconfigs in a monorepo - mixing `lib: ["dom"]` into a Node project (or forgetting it in a React project) causes false positives and negatives. Keep separate tsconfig per target environment.
- Ignoring `noUncheckedIndexedAccess` - it's not in the `strict` umbrella but is one of the most impactful checks. Enable it explicitly and handle the `T | undefined` returns with proper guards.
Tip
Tip
Practice tsconfig Deep Dive All Critical Options in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Visual architecture and concepts for tsconfig Deep Dive - All Critical Options
Practice Task
Note
Practice Task - (1) Write a working example of tsconfig Deep Dive All Critical Options 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 Deep Dive All Critical Options 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
- A well-understood `tsconfig.
- Using `moduleResolution: "node"` (legacy) - old Node resolution doesn't understand package.json `exports` map. Use `NodeNext` for Node projects, `Bundler` for Vite/webpack projects.
- Not separating browser and Node tsconfigs in a monorepo - mixing `lib: ["dom"]` into a Node project (or forgetting it in a React project) causes false positives and negatives. Keep separate tsconfig per target environment.
- Ignoring `noUncheckedIndexedAccess` - it's not in the `strict` umbrella but is one of the most impactful checks. Enable it explicitly and handle the `T | undefined` returns with proper guards.
Finished this lesson?