What is target in tsconfig.json for?

TypescriptTsconfigTranspiler

Typescript Problem Overview


What does target in tsconfig.json signify?

{
  "compilerOptions": 
  {
    "sourceMap": true,
    "target": "es5",
    "module": "commonjs",
    "jsx": "react",
    "moduleResolution": "classic",
    "lib": [ "es2015", "dom",  "es2017" ]
  }
}

Typescript Solutions


Solution 1 - Typescript

> I am quite new to Typescript. What does Target in tsconfig.json signify?

target signifies which target of JavaScript should be emitted from the given TypeScript. Examples:

target:es5

()=>null will become function(){return null} as ES5 doesn't have arrow functions.

target:es6

()=>null will become ()=>null as ES6 has arrow functions.

More

I also made a quick video on the subject .

Solution 2 - Typescript

Target changes the JavaScript version you are compiling to.

The options are available at https://www.typescriptlang.org/docs/handbook/compiler-options.html

In the spirit of trying to better understand how the target flag changes my code I compiled some test code to each of the different versions to have a better understanding of the differences.

https://github.com/aizatto/typescript-playground/tree/master/dist/test-async-main

I'm also keeping notes of what I should be targeting depending on what environment I am looking at

https://www.aizatto.com/notes/typescript

Solution 3 - Typescript

If your target is es2017 , that's the latest version with new library references to shared memory and string. Changing your target means changing the libraries with which your code compiles. If you want to keep the target a low version while supporting libraries referenced by higher versions, you may add the required library to the "lib" in tsconfig.json.

To know more about the libraries referenced in different versions, see this answer.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnkit RaonkaView Question on Stackoverflow
Solution 1 - TypescriptbasaratView Answer on Stackoverflow
Solution 2 - TypescriptaizattoView Answer on Stackoverflow
Solution 3 - TypescriptAshique razakView Answer on Stackoverflow