Jimmy Kane
Jimmy Kane

Reputation: 16826

TS config target and lib for Angular 8

First of all I kinda know my question will be closed as a duplicate but I cannot find an answer so far.

I am building an angular app based on Angular 8

What target and lib should I use and how are these related? Should lib and target for the tsconfig be at the same version? What are the benefits ?

I don't understand for example what is the difference from a config like this:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2015",
      "dom"
    ]
  }
}

To this:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

That both work fine.

Upvotes: 0

Views: 1046

Answers (1)

Leon Radley
Leon Radley

Reputation: 7672

I might be wrong, but i'll try to answer.

The target specifies what the typescript compiler will output for target ecmascript version.

for angular 8 i think this is set to esnext, because then webpack will compile it once more before you get your bundles.

And then using the new differential loading webpack will spit out two versions one in es5 for older browsers, and one for > es2015 browsers.

The libs are all the features that typescript will enable you to use when writing your code. so dom enables all dom typings, and es2018 would enable all new features that came in that version.

Angular does a good job of polyfilling the language features for you, but sometimes you will need to add polyfill packages to get newer apis working in older browsers.

I hope that clears it up a bit :)

Upvotes: 2

Related Questions