Skip to content

Increase default targets over time #47572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 tasks done
JoshuaKGoldberg opened this issue Jan 24, 2022 · 6 comments
Closed
5 tasks done

Increase default targets over time #47572

JoshuaKGoldberg opened this issue Jan 24, 2022 · 6 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Jan 24, 2022

Suggestion

πŸ” Search Terms

default target es3 es5

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Continuing #10117: can we increase the default TypeScript target to newer than ES3? Let's say, ES5 to start?

Starting suggestion: how about introducing these breaking changes with TypeScript's major version numbers?

  • Increase to ES2015 for 5.0
  • Increase to ES2016 for 6.0
    • Alternately, as TypeScript major versions have hit at roughly one every two years, it might make sense to jump two years per version and skip to ES2017
  • ...and so on

An alternate strategy would be bumping to ES5 first and pushing subsequent releases later. ES2015 is so well-supported, though, it'd be nice to skip straight to supporting let, const, etc.

πŸ“ƒ Motivating Example

I know the TypeScript team is loath to introduce breaking changes, especially when it comes to emit and default settings. Throwing in semantic versioning probably isn't doing this issue any favors either.

But!

  • ES2015 support is significantly better now than it was a few years ago. IE is reaching consumer EOL in June 2022. Per https://kangax.github.io/compat-table/es6 all desktop browsers, mobile browsers, and server browsers with >=1% market share have 100% ES2015 syntax support (I think?).
  • ES3 and ES5 emit are harder to read than ES2015+ because classes, for/of, and so on need to be transpiled
  • Many runtime APIs such as Array.from aren't supported in <= ES5

This may be a breaking change for projects that target old runtimes and use TypeScript's emit and don't specify target... but that's what major versions are for, right? πŸ˜‰

πŸ’» Use Cases

Increasing default targets to emit code much cleaner in modern browsers gives a nicer default output for new TypeScript projects. For beginners to TypeScript in particular, it makes the learning curve a little easier as they won't have to mess with configuration options to be able to use basic features.

@RyanCavanaugh RyanCavanaugh added In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Jan 24, 2022
@JacobMGEvans
Copy link

I feel like that tweet could be added as evidence lol

@styfle
Copy link
Contributor

styfle commented Mar 22, 2022

If this is going to introduce a breaking change, how about changing the default target to esnext instead? Then there would be no need to keep changing the default in the future and it would move typescript toward the goal of a type checker instead of transpiler.

@wojpawlik
Copy link

Consider also defaulting strict to true.

@RyanCavanaugh
Copy link
Member

Default target in 5.0 is now ES5 and I suspect we might have appetite for ES6 in 6.0

@styfle
Copy link
Contributor

styfle commented Feb 23, 2024

Thanks @RyanCavanaugh!

Can you comment on my suggestion about defaulting to target: "esnext" instead of bumping each release?

#47572 (comment)

@RyanCavanaugh
Copy link
Member

ESNext includes features that work in 0% of runtimes, like standard decorators. Seems very aggressive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants