Saturday, October 25, 2025
HomeLanguagesJavascriptWhat is the purpose of using tsconfig.json file ?

What is the purpose of using tsconfig.json file ?

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”
   ]

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS