1. include

  • Defines the directory where you want the files to be compiled

    • Default value: [“**/*”]

        // All files in the SRC directory and tests directory are compiled
        // ** indicates any folder, * indicates any file
        "include": ["src/**/*"."tests/**/*"]
      Copy the code

2. exclude

  • Define the directories that need to be excluded

    • Default: [“node_modules”, “boWER_components “,” jSPM_packages “] default: [“node_modules”, “bower_components”, “jSPM_packages “]

          // SRC files in the hello directory will not be compiled
          "exclude": ["./src/hello/**/*"]
      Copy the code

3. extends

  • Define inherited configuration files
    • // The current configuration file automatically contains all the configuration information in base.json in the config directory
      "extends": "./configs/base"
      Copy the code

4. files

  • Specifies a list of files to be compiled. Used only when there are fewer files to compile.

// The files in the list are compiled by the TS compiler

```json
    "files": [
        "core.ts",
        "sys.ts",
        "types.ts",
        "scanner.ts",
        "parser.ts",
        "utilities.ts",
        "binder.ts",
        "checker.ts",
        "tsc.ts"
    ]
```
Copy the code

compilerOptions

1. target
  • Sets the target version for ts code compilation

  • Optional value:

    • ES3 (default), ES5, ES6/ES2015, ES7/ES2016, ES2017, ES2018, ES2019, ES2020, ESNext
  • Example:

      // The ts code we wrote will be compiled into the ES6 version of js code
      "compilerOptions": {
          "target": "ES6"
      }
    Copy the code
2. module
  • Sets up the modular system used by compiled code

  • Optional value:

    • CommonJS, UMD, AMD, System, ES2020, ESNext, None, ES2015, ES6
  • Example:

    • "compilerOptions": {
          "module": "CommonJS"
      }
      Copy the code
3. lib
  • Specifies the libraries that the code runtime contains (the host environment, such as the dom library, document method, etc., is not set). This does not need to be changed in the browser environment, but only in the nodeJS environment.

  • Optional: lib specifies the libraries to be used in the project

‘es5’, ‘es6’, ‘es2015’, ‘es7’, ‘es2016’, ‘es2017’, ‘es2018’, ‘es2019’, ‘es2020’, ‘esnext’, ‘dom’, ‘dom.iterable’, ‘webworker’, ‘webworker.importscripts’, ‘webworker.iterable’, ‘scripthost’, ‘es2015.core’, ‘es2015.collection’, ‘es2015.generator’, ‘es2015.iterable’, ‘es2015.promise’, ‘es2015.proxy’, ‘es2015.reflect’, ‘es2015.symbol’, ‘es2015.symbol.wellknown’, ‘es2016.array.include’, ‘es2017.object’, ‘es2017.sharedmemory’, ‘es2017.string’, ‘es2017.intl’, ‘es2017.typedarrays’, ‘es2018.asyncgenerator’, ‘es2018.asynciterable’, ‘es2018.intl’, ‘es2018.promise’, ‘es2018.regexp’, ‘es2019.array’, ‘es2019.object’, ‘es2019.string’, ‘es2019.symbol’, ‘es2020.bigint’, ‘es2020.promise’, ‘es2020.sharedmemory’, ‘es2020.string’, ‘es2020.symbol.wellknown’, ‘es2020.intl’, ‘esnext.array’, ‘esnext.symbol’, ‘esnext.asynciterable’, ‘esnext.intl’, ‘esnext.bigint’, ‘esnext.string’, ‘esnext.promise’, ‘esnext.weakref’

  • Example:

      "compilerOptions": {
          "target": "ES6"."lib": ["ES6"."DOM"]."outDir": "dist"."outFile": "dist/aa.js"
      }
    Copy the code
4. outDir
  • The directory where the compiled file resides

  • By default, compiled JS files are located in the same directory as ts files. Setting outDir can change the location of compiled files

  • Example:

      // The compiled JS file will be generated in the dist directory
      "compilerOptions": {
          "outDir": "dist"
      }
    Copy the code
5. OutFile (usually not used, it is handled by webpack, etc.)
  • Compile all files into a JS file

  • By default, all code written in the global scope is merged into a JS file. If an import package or file is used in a JS file, you need to set the module value to None, System, or AMD, which merges the modules into the file altogether. Otherwise an error

  • Example:

     "compilerOptions": {
         "outFile": "dist/app.js"
     }
    Copy the code
6. allowJs
  • Whether to compile js files. The default is false
7. checkJs
  • Check whether the JS code is syntactically correct. The default is false

  • Example:

      "compilerOptions": {
          "allowJs": true."checkJs": true
      }
    Copy the code
8. removeComments
  • Delete comments

  • Default: false(not deleted)

9. NoEmit does not generate compiled files

It is used to check grammar. No file generation, less use

  • Default value: false

noEmitOnError
  • Do not compile if there are errors

  • Default value: false

8. Double check
  • strict
    • Enable all strict checks. The default value is true, which means all strict checks are enabled
  • alwaysStrict
    • Always compile code in strict mode, which is the default if import and export are used
  • noImplicitAny
    • The implicit any type is disallowed. If no type is set when defining parameters, the default is any
  • noImplicitThis
    • Disallow this with undefined type

          function test() {
              alert(this); // This is undefined this
          }
      Copy the code
  • strictBindCallApply
    • Strictly check the parameter lists for bind, call, and apply
  • strictFunctionTypes
    • Strictly check the type of the function
  • strictNullChecks
    • Strict null-checking
      var dom = document.getElementById('#test')
      dom.addEventListener('click'.function (){
          alert('hello');
      }); // dom may be empty, if strictNullChecks is true, the check will failThe solution1.plan1
      if(box1 ! = =null){
           box1.addEventListener('click'.function (){
               alert('hello');
           });
      }
     2.plan2box1? .addEventListener('click'.function (){
          alert('hello');
      });
    
    Copy the code
  • strictPropertyInitialization
    • Strictly check that the property is initialized

9. Extra checks
  • noFallthroughCasesInSwitch
    • Check that the switch statement contains the correct break
  • noImplicitReturns
    • Check that the function has no implicit return value
  • noUnusedLocals
    • Check for unused local variables
  • noUnusedParameters
    • Check for unused parameters
Senior 10.
  • allowUnreachableCode
    • Check for unreachable code
    • Optional value:
      • True, ignore unreachable code
      • False, unreachable code will cause an error
  • noEmitOnError
    • Do not compile if there are errors
    • Default value: false