Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท tsconfig: Language, Modules and Emit Options

TypeScript target option

Reference for the target compiler option: which JavaScript syntax TypeScript emits, how it differs from lib, downleveling, and choosing a target for Node and browsers.

target sets the JavaScript language version that tsc writes. Syntax newer than the target is rewritten into older equivalents (this is called downleveling); syntax the target already supports is left alone. Choose a value that matches the oldest runtime you ship to: es2022 or newer for current Node versions and evergreen browsers.

target only controls syntax: ??, **, class fields, async functions. It does not add built-in APIs such as Array.prototype.at or Object.groupBy; the lib option decides which of those the type checker knows about, and polyfills (if any) decide whether they exist at runtime. The target also changes some defaults: lib follows it when not set, and useDefineForClassFields is on for es2022 and higher.

JSON
{ "compilerOptions": { "target": "es2024" } }

Try it

The examples in this site compile with target set to es2024, so modern syntax passes through untouched.

TypeScript Syntax is kept as written

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript Class fields and private names

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

JSON
{ "compilerOptions": { "target": "es2022" } }
Value Meaning
es2015 ... es2025 Emit syntax of that ECMAScript edition. es6 is an alias for es2015.
esnext Emit the newest syntax the compiler knows. Output may not run on older runtimes.
es5, es3 Very old output. Removed or deprecated in recent releases; check your version before using them.

Command line: tsc --target es2022. If target is not set, the default depends on the version; set it explicitly instead of relying on it.

Usage notes

  • Match your runtime, not the newest edition. Node 24 and current browsers support everything up to es2024; a library for older environments may need es2020 or lower.
  • Features that need downleveling for old targets include optional chaining, ??, async/await, class fields, using declarations and decorators. Low targets generate helper code and make the bundle bigger.
  • Bundlers (esbuild, Vite, SWC) do their own downleveling. In those projects target often only drives type checking, and the real output target is set in the bundler.
  • Choose lib separately. target: "es2022" with lib: ["es2022", "dom"] is common for browser code.
  • useDefineForClassFields follows the target: from es2022 on, class fields use define semantics, which can change behavior of subclasses that redeclare a field.
  • The target for Node type stripping (node main.ts) is irrelevant, since Node does not downlevel at all.