tsconfig.json Configuration Basics in Typescript - Time & Space Complexity
When we use tsconfig.json, it controls how TypeScript compiles code. Understanding time complexity here means looking at how the compiler's work grows as the project size grows.
We want to know: How does the compile time change when we add more files or options?
Analyze the time complexity of the following tsconfig.json setup.
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"strict": true,
"outDir": "dist"
},
"include": ["src/**/*"]
}
This config tells TypeScript to compile all files in the src folder with strict checks and output to dist.
Look at what the compiler does repeatedly.
- Primary operation: Compiling each source file in the included folders.
- How many times: Once per file matched by the include pattern.
As you add more files in src, the compiler must process each one.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Compiles 10 files |
| 100 | Compiles 100 files |
| 1000 | Compiles 1000 files |
Pattern observation: The compile work grows directly with the number of files.
Time Complexity: O(n)
This means compile time grows in a straight line as you add more files.
[X] Wrong: "Adding more compiler options will always make compile time much slower."
[OK] Correct: Some options only change checks or output style without adding loops over files, so they don't always increase compile time significantly.
Knowing how tsconfig.json affects compile time helps you understand project scaling and build performance, a useful skill for real projects and teamwork.
"What if we add an exclude pattern to skip some files? How would the time complexity change?"