The tsconfig.json File
A tsconfig.json file marks the root of a TypeScript project and holds compiler options that control how your code is checked and compiled. You can create one automatically by running `tsc --init`.
With a tsconfig.json in place, you can simply run `tsc` with no arguments, and it will compile your whole project according to the settings you defined, such as which JavaScript version to target and how strict the type checking should be.
{
"compilerOptions": {
"target": "ES2020",
"outDir": "dist",
"strict": true
}
}Common options
`target` sets which JavaScript version to output (like ES2020). `outDir` sets where compiled files go. `strict` turns on a group of strict type-checking rules, which is strongly recommended.
Generating a config
Run `tsc --init` in your project folder to generate a tsconfig.json with helpful comments explaining each option, which you can then customize.
tsc --initCreated a new tsconfig.jsonGenerates a default configuration file in the current folder.
{
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"strict": true,
"outDir": "dist"
},
"include": ["src/**/*"]
}(no runtime output โ configuration file)This config compiles everything in src into ES2020 JavaScript inside a dist folder with strict checks.
Key points
- tsconfig.json defines the root and settings of a TypeScript project.
- `tsc --init` generates a starter configuration file.
- `strict: true` enables the most helpful type-checking rules.
- `outDir` and `target` control where and how code is compiled.
