tsconfig.json
tsconfig.json
contains compiler option for your TypeScript project.
tsc
will automatically look for tsconfig.json
in the current and parent folders.
You can also specify a different file by tsc -p <config file path>
.
Generate
tsconfig.json
can be generated by running tsc --init
.
Schema
http://json.schemastore.org/tsconfig
- If you found error or properties missing, give it some love at https://github.com/schemastore/schemastore/ by opening PRs
Json Completion for custom config files in VSCode
Add this to your .vscode/settings.json
:
// .vscode/settings.json
{
"json.schemas": [
{
"fileMatch": [
"tsconfig.*.json"
],
"url": "http://json.schemastore.org/tsconfig"
}
]
}
Guidelines
Build config
- Use
tsconfig.build.json
for build purpose, andtsconfig.json
for IDE. - In
tsconfig.json
, useexclude
. In
tsconfig.build.json
, usefiles
.Why? You typically would write test files but don't want to bundle them in your package.
tsconfig.build.json
uses thefiles
property allows you to have fine grain control on what to include in your package, whiletsconfig.json
uses theexclude
property so IDE can includes your test files in the project thus providing better completion support.For example:
// tsconfig.json { "compilerOptions": { // ... }, "exclude": [ "coverage", "dist", "node_modules" ] }
// tsconfig.build.json { "conpilerOptions": { // ... }, "files": [ "src/index.ts", "typings/index.d.ts" ] }
use the same
compilerOptions
on bothtsconfig.json
andtsconfig.build.json
Why? While some options does not apply for IDE, keeping them the same avoid confusion on whether something was missing or wrong when they are different.
tsconfig.json at project root
Use this to configure your development environment
Why? Some IDEs allow you to specific which configuration to use, but some does not. Thus, it is better to use this to configure development environment while using other configs for build and CI.
References
http://www.typescriptlang.org/docs/handbook/tsconfig-json.html http://json.schemastore.org/tsconfig