tsconfig.json
Run npx tsc in a folder, and how does the compiler know which files to check, how strict to be, or where to write the JavaScript? It reads one file: tsconfig.json. Everything about how your project compiles lives there.
The rule
tsconfig.json marks the project: which files, which options, which output.
The folder containing tsconfig.json is the root of a TypeScript project. When you run tsc without file names, it looks for this file in the current folder and then in parent folders.
A small configuration for the task tracker:
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"rootDir": "src",
"outDir": "dist",
"strict": true
},
"include": ["src"],
"exclude": ["src/**/*.test.ts"]
}The top-level keys answer "which files?":
include— folders or patterns to compile."src"means every TypeScript file undersrc/.exclude— patterns to leave out of whatincludematched. (node_modulesis excluded by default.)files— an exact list of files, used instead of or alongsideincludein small projects.extends— inherit settings from another config file, such as a shared base for several packages.
compilerOptions answers "how?":
rootDirandoutDir— where the sources live and where the.jsfiles go.src/tasks/list.tsbecomesdist/tasks/list.js, keeping the folder structure.targetandmodule— what kind of JavaScript to produce (the next lesson covers these).strict— how hard to check.
The file allows comments, unlike ordinary JSON, which is why tsc --init fills it with explanatory notes.
The shortcut
Read any tsconfig in two passes: "which files?" then "what options?"
Is it included?
src/tasks/list.tsis undersrc, whichincludelists. Yes.
A frequent confusion: exclude only filters what include matched. If an included file imports an excluded one, the compiler still reads the imported file.
Drills
Answer fast — trust the rule.
Which key holds settings such as strict and outDir?
With rootDir: "src" and outDir: "dist", where is src/api/tasks.ts written?
What does "extends": "./tsconfig.base.json" do?
How does running npx tsc with no arguments find its settings?
Remember
- tsconfig.json marks the project: which files, which options, which output.
- Read it in two passes: include/exclude/files first, then compilerOptions.
- Trap:
excludedoes not stop a file from being compiled if an included file imports it.
