What is the purpose of using tsconfig.json file ?
Last Updated :
16 May, 2022
tsconfig.json file is a file of JSON format which allows us to point the root level files and different compiler options to setup that require to compile a TypeScript based projects. The existence of this file in a project specifies that the given directory is the TypeScript project folder root.
The tsconfig.json file mainly consists of the information for the following:
- CompilerOptions
- CompileOnSave
- Files
- Include
- Exclude
Let's take an example file of tsconfig.json file and understand the purpose of each of its parts.
tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"module": "system",
"noImplicitAny": true,
"removeComments": true,
"allowUnreachableCode": false,
"strictNullChecks": true,
"outFile": "../JS/TypeScript/HelloWorld.js",
"sourceMap": true
},
"files": [
"program.ts",
"sys.ts"
],
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"src/**/*.spec.ts"
]
}
CompilerOptions - It is a property that allows specifying additional options to the TypeScript compiler. Given a list of a few optional settings section of the compilerOptions property that is needed most of the time:
- listFiles
- module
- outDir
- outFile
- rootDir
- sourceRoot
- allowUnreachableCode
- allowJs
- noImplicitUseStrict
- strictNullChecks
{
"compilerOptions": {
"module": "system",
"noImplicitAny": true,
"removeComments": true,
"allowUnreachableCode": false,
"strictNullChecks": true,
"outFile": "../JS/TypeScript/HelloWorld.js",
"sourceMap": true
}
}
CompileOnSave - It is a property that can be used to instruct the IDE to automatically compile the given TypeScript files and generate the output for the same.
{
"compileOnSave": true,
"compilerOptions": {
"module": "system",
"noImplicitAny": true,
"removeComments": true,
"allowUnreachableCode": false,
"strictNullChecks": true,
"outFile": "../JS/TypeScript/HelloWorld.js",
"sourceMap": true
}
}
Files - It is a property that gives a list of TypeScript files that will be included by the compiler. The URL of the files can be both relative or absolute.
"files": [
"program.ts",
"sys.ts"
]
Include - It is a property that allows you to include a list of TypeScript files using the glob wildcards pattern.
"include": [
"src/**/*"
]
Exclude - It is a property that allows you to exclude a list of TypeScript files using the glob wildcards pattern.
"exclude": [
"node_modules",
"src/**/*.spec.ts"
]
Similar Reads
What is the purpose of the 'node_modules' folder ? The node_modules folder is a directory in NodeJS projects that stores third-party libraries and dependencies. It's essential for managing dependencies, which are packages or modules that a NodeJS project relies on. When you install a package using npm or Yarn, these tools download the package along
5 min read
What is the using Keyword in Typescript ? The new version of TypeScript introduces support for the âusingâ keyword used for the Explicit Resource Management feature in the ECMAScript, the using keyword is a keyword that aims to sort the facility for âcleanupâ after creating any object. The need for âusingâ keywords in both TypeScript and Ja
2 min read
What is the purpose of module.exports in node.js ? The module.exports is actually a property of the module object in node.js. module. Exports is the object that is returned to the require() call. By module.exports, we can export functions, objects, and their references from one file and can use them in other files by importing them by require() meth
3 min read
What is the purpose of process object in Node.js ? A process object is a global object available in the Node.js environment. It is globally available. We do not have to use the require() to import the module of the process object. The "process" object use to get current Node.js process details & also give control over that process. Properties of
2 min read
What is the Purpose of Exports Array in NgModule? NgModule is a class marked by the @NgModule decorator. It identifies the module's own components, directives, and pipes, making some of them public, through the exports property, so that external components can use them. The @NgModule decorator takes a metadata object as an argument. This object con
3 min read