tsconfig.json is the configuration file of a TypeScript project.
It tells the TypeScript compiler (tsc) how to compile your TypeScript code into JavaScript and which type-checking rules to follow.
For example, it controls:
- Which JavaScript version should be generated.
- Which module system should be used.
- Where TypeScript source files are located.
- Where compiled JavaScript files should be stored.
- How strictly TypeScript should check your code.
- Which files should be included or excluded.
1. Creating tsconfig.json
Inside your project folder, run:
It generates a tsconfig.json file containing compiler options and documentation.
2. compilerOptions
This is the main configuration section.
Example:
A. target
Specifies which JavaScript version TypeScript should generate.
B. module
Specifies which module system should be used in the generated JavaScript.
C. strict
This is one of the most important options.
It enables a group of strict type-checking options.
D. rootDir
Specifies the directory containing your TypeScript source files.
E. outDir
Specifies where the compiled JavaScript files should be generated.
3. Other important compiler options
Option | Purpose |
|---|---|
| Check types without generating JS |
| Don't generate JS if errors exist |
| Generate source map files |
| Remove comments from generated JS |
| Simplifies interoperability with CommonJS modules |
| Skip type checking of declaration files |
| Enforce consistent filename casing |
| Generate |
noEmit
TypeScript checks your code but doesn't generate JavaScript.
Useful when another tool, such as a bundler, handles compilation.
sourceMap
Generates .js.map files.
These help debugging tools map generated JavaScript back to the original TypeScript source.
esModuleInterop
Helps with importing CommonJS packages.