-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Update implied default for module based on target #63076
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Updates TypeScript’s implied default module compiler option to better align with the configured target, enabling more modern module semantics (e.g., top-level await) when targeting newer ECMAScript versions.
Changes:
- Adjusts computed default for
modulebased ontargetwith new thresholds (es2020/es2022/esnext). - Updates a single baseline affected by the new default (top-level await now permitted under
@target: esnextdue to implicitmodule: esnext).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/compiler/utilities.ts | Updates computed default module selection logic to track target more closely (es2015/es2020/es2022/esnext). |
| tests/baselines/reference/awaitInNonAsyncFunction.errors.txt | Updates error baseline impacted by the new implicit module default enabling top-level await under @target: esnext. |
| const target = _computedOptions.target.computeValue(compilerOptions); | ||
| if (target === ScriptTarget.ESNext) { | ||
| return ModuleKind.ESNext; | ||
| } | ||
| if (target >= ScriptTarget.ES2022) { |
Copilot
AI
Jan 31, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change alters the implied module value based on target (including enabling top-level await for @target: esnext via the implicit module: esnext). It would be good to add a focused compiler test that explicitly asserts the new default mapping at the key boundaries (es2015/es2020/es2022/esnext), rather than relying on incidental baseline changes in unrelated tests.
|
@typescript-bot test top800 |
|
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
|
@jakebailey Here are the results of running the top 800 repos with tsc comparing Everything looks good! |
If
moduleis explicitly configured, we do what the config says (duh).Otherwise, if target is ES5, then
module=commonjs. Iftargetis ES2015+, thenmodule=es2015.This PR changes the default module such that:
target=esnext, thenmodule=esnext.target>=es2022, thenmodule=es2022.target>=es2020, thenmodule=es2020.target>=es2015, thenmodule=es2015.module=commonjs.This leads to potentially less strange/misaligned behavior.
Only one test changes. I could find which features each module mode enables to verify these rules, if desired.