tsconfig.json has well over a hundred options, but a good config is mostly a few decisions. Get these right and the rest can stay on defaults.
1. How imports resolve: module + moduleResolution
This is the setting people get wrong most often. Pick by who runs the output:
| Runtime | module | moduleResolution |
|---|---|---|
| Node runs the compiled JS | nodenext | nodenext |
| Vite / webpack / esbuild / Bun bundles it | esnext | bundler |
With nodenext, TypeScript follows Node's real rules. That means relative ESM imports need extensions (./util.js), and "type" in package.json decides ESM vs CommonJS.
2. What JavaScript to emit: target and lib
target sets the syntax level of the output. ES2022 or newer is safe for current Node LTS versions and evergreen browsers. lib sets which built-in APIs the type checker knows about. Add "DOM" for browser code.
3. How strict: strict plus a few extras
"strict": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"verbatimModuleSyntax": true
- strict turns on the core family (
strictNullChecks,noImplicitAny, …). Enable it on day one. - noUncheckedIndexedAccess types
arr[i]asT | undefined, which catches real bugs. - verbatimModuleSyntax makes you write
import typefor type-only imports, so emitted imports are predictable.
4. Output: outDir, declaration, sourceMap
For a library, set "declaration": true so consumers get .d.ts files, and point package.json exports.types at them. rootDir + outDir keep the src/ → dist/ layout tidy.
5. Aliases: paths
"paths": { "#lib/*": ["./src/lib/*"] }
Remember paths only affects type checking. Mirror it in package.json "imports" (which is why the # prefix works well) or in your bundler config.
6. Sharing and monorepos: extends and references
"extends": "@tsconfig/node22/tsconfig.json"inherits a maintained base.- In a monorepo, each package sets
"composite": true, and a root tsconfig lists them inreferences. Build withtsc -b.
Security and correctness notes
skipLibCheck: truespeeds builds but hides type errors inside dependencies.- A clean type check is not runtime validation. Validate untrusted JSON with a schema (see the JSON Schema guide).
Open the tsconfig template and ask the workspace to "switch this to a bundler setup for Vite" or "add a path alias", then diff the result.