Skip to content

TSConfig

tsconfig.json is the configuration file that controls how the TypeScript compiler behaves for a project β€” which files to include, what JavaScript version to compile down to, how strict the type checking should be, and where to output the compiled files. Running tsc with no arguments looks for this file automatically in the current directory.

{
"compilerOptions": {
"target": "ES2022", // JavaScript version to compile down to
"module": "ESNext", // module system to use in the output
"strict": true, // enables all strict type-checking options
"outDir": "./dist", // where compiled JS files go
"rootDir": "./src", // where source TS files live
"esModuleInterop": true, // smoother interop with CommonJS modules
"skipLibCheck": true // don't type-check .d.ts files in node_modules (faster builds)
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
Terminal window
tsc # compiles according to tsconfig.json in the current dir
tsc --init # generates a starter tsconfig.json

Leaving "strict": false (or omitting it, since it’s false by default) on a real project β€” this silently disables a whole set of valuable checks, including strictNullChecks, which is often the single most bug-catching option TypeScript offers.

// Without strict mode, this compiles with no error:
function getLength(s: string) {
return s.length;
}
getLength(null); // no compile error without strictNullChecks -- crashes at runtime
// With "strict": true, TypeScript catches this immediately:
// Error: Argument of type 'null' is not assignable to parameter of type 'string'.
  1. What does the "strict": true compiler option actually do?

    AnswerIt's a shorthand that enables a whole family of stricter type-checking options at once, including strictNullChecks, noImplicitAny, and others β€” widely considered the single most important setting for catching real bugs.
  2. What’s the difference between include and exclude in tsconfig.json?

    Answerinclude specifies which files/patterns the compiler should process; exclude removes files/patterns from that set (commonly used to skip node_modules and build output directories).
  3. What does the target compiler option control?

    AnswerWhich JavaScript language version the compiled output targets β€” e.g. "ES2022" β€” determining which newer JS syntax gets downleveled versus passed through as-is.