Skip to main content

Configuration (tsconfig.json)

When building a large TypeScript project, you won't use tsc index.ts repeatedly. Instead, you'll compile entire massive folders of .ts files synchronously.

To manage compiler rules, TypeScript uses a configuration file known as tsconfig.json.

Running the initialization command:

tsc --init

...generates a sprawling tsconfig.json file.

Crucial Compiler Options

Here are the most important properties you will interact with in a standard React or Node application:

{
"compilerOptions": {
/* Modules & Targets */
"target": "ES2022", // The version of JS the compiler outputs (e.g., ES5, ES2022)
"module": "CommonJS", // Important for Node backward compatibility
"jsx": "react-jsx", // Transforms TSX files into standard React calls

/* Paths */
"outDir": "./dist", // Where the compiled pure .js files will be dumped
"rootDir": "./src", // Where TypeScript should search for source .ts files

/* Strictness */
"strict": true, // ENABLES ALL STRICT TYPE-CHECKING RULES!
"noImplicitAny": true, // Prevents TypeScript from randomly guessing 'any' types
"strictNullChecks": true, // Makes Null and Undefined independently strict

/* Interoperability */
"esModuleInterop": true, // Smooths out imports between ES modules and CommonJS
"skipLibCheck": true // Speeds up compile times by not type-checking node_modules
},
"include": ["src/**/*"], // Tell TS which folders to compile
"exclude": ["node_modules", "**/*.spec.ts"] // Folders specifically to ignore
}

Pro Tip: The "strict": true flag is the most important field. Without it, you are basically writing expensive Vanilla JS. Always keep strict mode enabled to ensure type safety!