The target setting changes which JS features are downleveled and which are left intact. For example, an arrow function () => this will be turned into an equivalent function expression if target is ES5 or lower. Changing target also changes the default value of lib .
The "target" property is used to specify the JavaScript version your TypeScript code will eventually compile into. The "module" property specifies the type of the module syntax your compiled (TS-->JS) code will use.
json file in a directory indicates that the directory is the root of a TypeScript project. The tsconfig. json file specifies the root files and the compiler options required to compile the project.
However, right now, according to Google, 95% of global web traffic comes from web sites that support at least es2017 feature set. This means that we can target es2017 as our transpile version and be pretty confident that it will be supported.
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.
I also made a quick video on the subject 🌹.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With