Sub topic 1
What tsconfig.json Does and How `tsc` Finds It
Prerequisites
You should know basic TypeScript syntax, JSON, and how to run commands with Node.js and npm installed.
A tsconfig.json file tells the TypeScript compiler, tsc, which source files to read, which JavaScript version and module format to produce, and which checks to apply.
When you run tsc without input files, it looks for tsconfig.json in the current directory. Use --project when the configuration is elsewhere:
npx tsc --project config/tsconfig.jsonIf you pass source files directly, such as npx tsc src/index.ts, the command uses those files instead of discovering a project configuration.
Choosing Which Files Are Compiled
Use files for an explicit list. Use include for patterns, and exclude to remove matching files from the included set.
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"rootDir": "src",
"outDir": "dist"
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
}An imported file can still enter the program even when it does not match include. Therefore, file selection also follows imports.
Matching `target` and `lib` to Your Runtime
target selects the JavaScript syntax that TypeScript emits. Choose a version supported by your runtime. lib selects the type definitions available during checking, such as DOM APIs or modern JavaScript features. These definitions do not add runtime features.
Module Formats and Module Resolution
module controls the emitted module format. NodeNext follows Node.js rules and works well for projects using modern Node package metadata. Module resolution controls how imports map to files and packages. It normally should match the module system.
Controlling Emitted Output
rootDir describes the source tree, while outDir receives compiled files. noEmit checks types without writing JavaScript. sourceMap creates debugger mappings, and declaration emits .d.ts type declaration files.
Exercise
Which option should you use to type-check a project without creating JavaScript files?
Show answer
Set "noEmit": true in compilerOptions, or run npx tsc --noEmit.