Paths, outDir and rootDir

Path Aliases

paths replaces long relative imports (../../../lib/db) with aliases (@/lib/db). TypeScript only uses them for type checking; the bundler or runtime must understand them too (Next.js and Vite read tsconfig paths; for plain Node use tsc-alias, tsconfig-paths or Node "imports" with #lib/*).

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"],
      "@shared/*": ["../shared/src/*"]
    }
  }
}
import { db } from "@/lib/db";            // instead of "../../../lib/db"
import type { Money } from "@shared/types";

outDir and rootDir

rootDir: "src"            outDir: "dist"
src/                      dist/
  main.ts          tsc      main.js       main.js.map
  orders/order.ts  ---->    orders/order.js
  types.d.ts                (d.ts files are not copied)
  • rootDir: the folder whose structure is mirrored in the output.
  • outDir: where JavaScript goes. Without it, .js files are written next to .ts files.
  • include / exclude: which files are part of the program (exclude tests from the production build).
  • declaration + declarationDir: emit .d.ts for libraries; sourceMap: map stack traces back to .ts.