tsconfig.json
tsconfig.json marks the root of a TypeScript project and says which files to compile and with which compiler options.
Connect project files and compiler settings through one reproducible configuration.
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.