Advertisement
Beginner TypeScript, tsconfig & Compiler Options

What does the 'target' compiler option control, and how does it affect which JavaScript features get downleveled?

Short answer

'target' specifies which ECMAScript version the compiled JavaScript output should conform to — newer language features (like optional chaining, async/await, or classes) get automatically transformed ('downleveled') into older equivalent syntax if the target doesn't natively…

Save TypeScript mock interview
Advertisement
AModel answer
'target' specifies which ECMAScript version the compiled JavaScript output should conform to — newer language features (like optional chaining, async/await, or classes) get automatically transformed ('downleveled') into older equivalent syntax if the target doesn't natively support them, ensuring compatibility with older runtimes.
Example

// target: 'ES5' downlevels arrow functions, classes, async/await, etc. into ES5-compatible code // target: 'ES2020' keeps most modern syntax as-is, assuming a modern runtime

Real-world example
Choosing 'ES2020' or newer for a modern browser/Node.js target versus 'ES5' for supporting very old browsers like IE11.
Likely follow-ups
  • Does a higher 'target' setting affect TYPE CHECKING strictness, or only the shape of the emitted JavaScript?
Related topics