If a tsconfig.json file exists in a directory, it is assumed to be the TypeScript root directory, which specifies the root file and compilation options used to compile the project.

Files, include, and exclude specify compilation

Json: tsconfig.json: tsconfig.json: tsconfig.json: tsconfig.json: tsconfig.json: tsconfig.json: tsconfig.json: tsconfig.json: tsconfig.json: tsconfig.json: tsconfig.json

  • 1, use,filesconfiguration

The files attribute is used to specify which files to compile. You can configure an arraylist that contains the relative or absolute path of the specified files. The compiler will compile only files listed in files when compiling, depending on whether the include option is set. By default, files in the root directory and all subdirectories are compiled. The path listed here must be the specified file, not a folder, for example just want to compile demo.ts and test.ts files:

 {
   "compilerOptions": {
     //any something
     / /...
   },
   "files": ["demo.ts"."test.ts"],}Copy the code
  • 2, use,includeconfiguration

The include attribute specifies the list of paths to compile and include. The difference between the include attribute and files is that the paths can be folders or files. You can use relative or absolute paths, for example, you want to compile all SRC ts files:

 {
   "compilerOptions": {
     //any something
     / /...
   },
   "include": ["src/*"],}Copy the code
  • 3, use,excludeconfiguration

Exclude excludes files that do not compile. It can also specify a list of files or folders, relative or absolute paths, like include. For example, exclude all ts files under node_modules:

 {
   "compilerOptions": {
     //any something
     / /...
   },
   "exclude": ["node_modules"],}Copy the code

Files specifies a list of relative or absolute file paths, while the include and exclude attributes specify a list of glob match patterns for files. The supported glob wildcards are:

  • *Matches 0 or more characters (excluding directory delimiters)
  • ?Matches an arbitrary character (excluding the directory separator)
  • * * /Recursively matches any subdirectory

Extends Inheritance configuration

The tsconfig.json file can use the extends property to specify a path to another tsconfig.json file that inherits the configuration from this configuration file, overwriting the configuration defined in the current file if the inherited configuration and the current file properties overlap. configs/base.json:

  { 
    "compilerOptions": {
      //any something
      / /...
    },
    "files": ["main.ts"]}Copy the code

tsconfig.json:

  { 
    "compilerOptions": {
      //any something
      / /...
    },
    "include": ["src/**/*"]."extends": ["./configs/base"]}Copy the code

CompileOnSave is compiled on save

Setting compileOnSave to true allows the IDE to recompile the build file from tsconfig.json while saving the file. This feature requires Visual Studio 2015, TypeScript1.8.4 or above, and the atom-typescript plug-in installed

  { 
    "compileOnSave": true."compilerOptions": {
      //any something
      / /...}}Copy the code

CompilerOptions Compilation options

The tsconfig.json file provides a large number of configuration items. The following are only some of the configuration items

options

type The default value instructions
target string ES3 The version standard used for compiling the results. Value containsES3.ES5.ES6/ES2015.ES2016.ES2017.ES2018.ES2019.ES2020.ESNext
module string target === ES6 ? ES6 : commonjs Modular standards used for compiling results:None.CommonJS.AMD.System.UMD.ES6/ES2015.ES2020.ESNext
jsx string preserve The specifiedjsxThe development environment for which the code is used:preserve.react-native.react
outDir string Specifies the location of the compiled file. If this is not specified, the output file is stored in the same directory as the compiled file
rootDir string Used to specify the root directory for compiling files. The compiler looks for entry files in the root directoryrootDirIt will not load all the files into it, but it will not stop compiling
baseUrl string Set the base directory for resolving non-relative module names, which are not affected by relative modulesbaseUrlThe influence of
paths object Module name to based onbaseUrlIs a list of path mappings
sourceMap boolean false Whether to generatesourceMapThe file, this is the file that holds the position of the code after the transformation, and the corresponding position before the transformation. With this, when something goes wrong, the breakpoint tool can display the original code directly, rather than the converted code
allowJs boolean false Whether thejsFile compilation
checkJs boolean false Specifies whether to check and reportjsError in file
removeComments boolean false Used to specify whether to delete comments from the compiled filetrueThen delete the comment
noEmit boolean false Whether to not generate a compile file
strict boolean false Whether to enable strict check
alwaysStrice boolean false Whether to enable strict mode for compiled files
noImplicitAny boolean false Whether implicit any is not allowed, defaultfalse(allow)
noFallthroughCasesInSwitch boolean false checkswitchThe statement contains the correctbreak
noImplicitReturns boolean false Check if the function returns a value, set to true, and prompt if the function does not return a value
noUnusedLocals boolean false Whether to check for unused local variables
strictNullChecks boolean false Whether to strictly check for null values, which may benullThe place where
strictFunctionTypes boolean false Whether the type of the function is strictly checked
strictPropertyInitialization boolean false Whether to strictly check whether the property is initialized
allowSyntheticDefaultImports boolean false Whether default imports are allowed for modules that do not contain default exports. This option does not affect generated code, only type checking
resolveJsonModule boolean false Is it allowed to putjsonThe file is parsed as a module
isolatedModules boolean false Whether to treat each file as a separate module