TypeScript Tsconfig Options
Configure tsconfig compiler options for strict type safety, modular module resolution, paths, and build outputs.
TL;DR
- Generate starter configuration files quickly using
tsc --initin projects. - Enable
strictmode to catch the most critical type errors. - Configure
includeandexcludearrays to control compiled source files.
Project Initialization
Generate starter configCreate standard starter configuration.
// Run from terminal:
// tsc --initCompiler options blockRoot object containing compiler flags.
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext"
}
}Type check without emitValidate types without generating files.
// Run in terminal or CI:
// tsc --noEmitExtend shared configsInherit options from a base config.
{
"extends": "@tsconfig/node20/tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
}
}Strict Type Checking
Master strict flagTurn on all strict type checking flags.
{
"compilerOptions": {
"strict": true
}
}Strict null checksDisallow implicit null or undefined.
{
"compilerOptions": {
"strictNullChecks": true
}
}No implicit anyRequire explicit types for inferred any.
{
"compilerOptions": {
"noImplicitAny": true
}
}Strict property initEnsure class properties are initialized.
{
"compilerOptions": {
"strictPropertyInitialization": true
}
}Emit and Target Control
ECMAScript targetSpecify target JavaScript output version.
{
"compilerOptions": {
"target": "ES2022"
}
}Module code generationSpecify module system for emit.
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext"
}
}Output directoryRedirect emitted JavaScript files.
{
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
}
}Declaration emitGenerate type definition files.
{
"compilerOptions": {
"declaration": true,
"declarationMap": true
}
}File Inclusion and Paths
Include source globsSpecify source file match patterns.
{
"include": ["src/**/*", "tests/**/*"]
}Exclude build foldersIgnore dependency and output folders.
{
"exclude": ["node_modules", "dist"]
}Path mapping aliasesMap import specifiers to directories.
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}Root directory guardEnforce single directory root structure.
{
"compilerOptions": {
"rootDir": "./src"
}
}Interop and Performance
ES module interopEnable default imports from CommonJS.
{
"compilerOptions": {
"esModuleInterop": true
}
}Skip library checkSkip type checking in declaration files.
{
"compilerOptions": {
"skipLibCheck": true
}
}Resolve JSON modulesPermit importing JSON file data.
{
"compilerOptions": {
"resolveJsonModule": true
}
}Incremental buildsCache build state to speed recompilation.
{
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": "./.tsbuildinfo"
}
}Tips
- Enable
skipLibCheckin projects to prevent redundant type-checking across large third-party declaration files and boost compilation performance. - Set
noEmitOnErrorto true during local builds to prevent JavaScript output generation whenever compilation encounters existing type diagnostics.
Warnings
- Configuring
pathsaliases intsconfig.jsononly satisfies the compiler; you must also configure bundler resolve plugins for runtime execution. - Changing
targetormodulemid-project can trigger subtle runtime polyfill incompatibilities across current browsers and legacy Node runtimes.
In Practice
A complete production-ready tsconfig.json setup balancing safety, standard module resolution, and fast compilation.
- Define output target and module resolution strategy.
- Activate complete strict type checking rules.
- Configure source input directories and path aliases.
- Optimize build performance with declaration caching.
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"noUncheckedIndexedAccess": true,
"rootDir": "./src",
"outDir": "./dist",
"declaration": true,
"skipLibCheck": true,
"baseUrl": ".",
"paths": { "@/*": ["src/*"] }
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}FAQ
Setting strict: true activates a suite of compiler safety flags simultaneously, including noImplicitAny, strictNullChecks, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, noImplicitThis, and useUnknownInCatchVariables. It provides the strongest type safety baseline for new codebases.
The target option specifies the ECMAScript version of output JavaScript (such as ES2022), determining which syntax features like classes or async/await are downleveled. The module setting specifies the module code generation format (such as NodeNext or ESNext) controlling how imports and exports are emitted.
Path aliases use baseUrl and paths mappings under compilerOptions. For example, mapping @/* to src/* lets you write clean imports like @/components/Button. However, TypeScript does not rewrite import paths during emission, so your bundler or runtime must also configure matching aliases.
Setting moduleResolution: 'bundler' tells TypeScript to emulate how bundlers like Vite, esbuild, and Webpack resolve package exports and extensions. It allows extensionless imports and respects package export maps without enforcing Node.js module specifier rules.
The include array lists glob patterns for files TypeScript should compile (such as src/**/*). The exclude array filters out unwanted directories like node_modules or dist. If include is omitted, TypeScript defaults to including all .ts files under the root directory.