Search code examples
javascriptnode.jstypescriptecmascript-6ecmascript-2020

Effect of TARGET property inside tsconfig.json


Below is the tsconfig.json of my project.

{
    "compilerOptions": {
        "module": "commonjs",
        "esModuleInterop": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "allowSyntheticDefaultImports": true,
        "strict": true,
        "target": "es6",
        "noImplicitAny": true,
        "moduleResolution": "node",
        "sourceMap": true,
        "outDir": "dist",
        "baseUrl": ".",
        "typeRoots": [
            "src/types",
            "node_modules/@types",
        ]
    },
    "include": [
        "src/**/*"
    ]
} 

My Typescript version is "typescript": "^3.9.5" and Node version us ts-node": "^8.10.2".

I just want to confirm if i change my target inside tsconfig.json file from "target": "es6" to "target": "es2020"`.How will it effect my current project or i am good.


Solution

  • TypeScript is a superset of ES6, so you’re essentially writing TS code using ES6 version of JavaScript. However, when compiled, the resulting JS code can be in ES5 or earlier. You need to define which version of JS the compiler should transpile into. This can be set using target option