About angular application tsconfig Target attribute in JSON

Time:2022-3-9

I created an angular application, which automatically generates tsconfig In the JSON file, the target is es2017 and the module is es2018

About angular application tsconfig Target attribute in JSON

In Spartacus applications, the target is only Es5:
About angular application tsconfig Target attribute in JSON

Modern browsers support all ES6 features, so ES6 is a good choice. If your code is deployed to an older environment, you can choose to set a lower target, or you can choose to set a higher target if your code is guaranteed to run in a newer environment.

The goal setting changes, which JS features are degraded and which remain unchanged. For example, if the target is Es5 or earlier, the arrow function () = > this will be converted to an equivalent function expression.

For example, after Spartacus ng build came out JS file, all arrow functions are converted to normal function usage:
About angular application tsconfig Target attribute in JSON

About angular application tsconfig Target attribute in JSON

The default value of Lib will also change. You can “mix and match” target and library settings as needed, but for convenience, you can only set targets.

For developer platforms like node, the target has a baseline, which depends on the type of platform and its version. You can find tsconfig of a group of community organizations in tsconfig / bases, which contains the configuration of common platforms and their versions.

The special esnext value refers to the maximum version supported by your typescript version. This setting should be used with caution because it does not mean the same thing between different versions of typescript and makes upgrades more unpredictable.

By default, all visible “@ types” packages are included in your compilation. Node of any closed folder_ Packages in modules / @ types are considered visible. For example, this means/ node_ modules/@types/、../ node_ modules/@types/、../../ node_ Modules / @ types /, etc.

If a type is specified, only the listed packages will be included in the global scope. For example:

{
  "compilerOptions": {
    "types": ["node", "jest", "express"]
  }
}

This tsconfig The JSON file will contain only/ node_ modules/@types/node、./ node_ Modules / @ types / jest and/ node_ modules/@types/express。 node_ Other packages under modules / @ types / * will not be included.

More Jerry’s original articles are: “Wang Zixi”:
About angular application tsconfig Target attribute in JSON

Recommended Today

JS generate guid method

JS generate guid method https://blog.csdn.net/Alive_tree/article/details/87942348 Globally unique identification(GUID) is an algorithm generatedBinaryCount Reg128 bitsNumber ofidentifier , GUID is mainly used in networks or systems with multiple nodes and computers. Ideally, any computational geometry computer cluster will not generate two identical guids, and the total number of guids is2^128In theory, it is difficult to make two […]