"target"

The JavaScript version the compiler turns your code into.

On this page

Example

#
JSON
{
  "compilerOptions": {
    "target": "ES2022",
    "lib": ["ES2022", "DOM", "DOM.Iterable"]
  }
}

Definition and usage

#

The target option specifies which language version the compiler should generate, for example ES2017, ES2022, or ESNext. Newer syntax that isn’t available in the chosen version is rewritten into an older form, where possible.

The value also affects the default set of standard library types (lib). With ES2022, for example, the types for Array.prototype.at() and Object.hasOwn() are available.

In projects with a bundler (Vite, Next.js, webpack), the build tool usually does the transpilation, and target in tsconfig is mainly used for type checking. Set it to a version supported by the browsers or the Node.js environment you’re targeting.

Syntax

#
Syntax
"target": "ES2022"

Good practices

#
  • For modern browsers and Node.js 20+, ES2022 is a safe choice.
  • The lib option lets you choose exactly which types are available, e.g. add DOM in a browser project.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.