Skip to content

Change default --target to esnext #62198

@DanielRosenwasser

Description

@DanielRosenwasser

The nature of TypeScript has changed in the last decade, where "evergreen runtimes" are now the norm. While it's true that there is often a rollout gap for features before they can safely be adopted, the current default target of es5 is an extreme way of serving those developers. What's more, --target es5 will no longer be supported in 7.0, and will be deprecated in 6.0 (see #62196).

While we do believe that most people do end up specifying a --target other than the default, that default is likely closer to esnext than es5 (or even es2015) these days. And we want to encourage that.

Specifying esnext as a target:

  • helps avoid some of the cursed behaviors that are on for older targets
  • avoids users unnecessarily downleveling their code
  • feels less arbitrary than picking some newer target
  • reinforces the key value prop that TypeScript has focused on - that TypeScript is just JavaScript with type syntax.

There are some "dangers" here. Any code that does not specify a target will have different JavaScript output which may occasionally differ in semantics (due to semantic differences from downleveled code, things like useDefineForClassFields, or even divergences in how engines support newer features). Certain code like decorators (not currently supported in any major engine) will not work either.

Knowing how to reconfigure TypeScript for this change may be a challenge. Users will often be able to look for tsconfig.json, tsconfig.*.json, jsconfig.json, files to explicitly specify a target, but they can't just look for the string "target" anywhere because the entire problem is that it was never specified! Because TypeScript configuration can be contained in JS objects and then fed through our API, and any generated errors can be ignored, this may make upgrades particularly difficult. Users should look for calls to APIs such as createProgram, getEmitOutput, transpile, transpileModule, and transpileDeclaration.


See more discussion around 6.0 deprecations/changes at #54500.

Metadata

Metadata

Labels

Breaking ChangeWould introduce errors in existing codeCommittedThe team has roadmapped this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions