Cài đặt target cho Typescript

When setting up any Typescript project, we will working at least once with tsconfig file. It is a important file that we should understand deeply to know how Typescript work behind the scenes.

First glance, it is a so simple json file with settings

{
"compilerOptions": {
"outDir": "dist",
"target": "ES2015",
"moduleResolution": "Node"
},
"include": ["src"]
}

target will let us know the version of Javascript that support when we compile code form Typescript to Javascript. There are many choices that reflects that growth of Javascript. Popular choice is es6es2016

default : es3
allowed: es3 | es5 | es6/es2015 | es2016 | es2017 | es2018 | es2019 | es2020 | es2021 | es2022 | esnext

Some features only support when we chose the right version of Javascript like below

  • Promise constructor support in ES2015
  • async/await support in ES2017
  • static private support in ES2022

A issue will be raise when we use the old target for a new code-base that not support to compile.

We should check the settings in target to make sure we understand our code after compiling.

Leave a Reply

Your email address will not be published. Required fields are marked *