Skip to content

fix: remove false tslib requirement for native #private fields at ES2022+ - #63751

Closed
Erfan (ErfanBagheri404) wants to merge 1 commit into
microsoft:mainfrom
ErfanBagheri404:fix/importHelpers-private-fields
Closed

fix: remove false tslib requirement for native #private fields at ES2022+#63751
Erfan (ErfanBagheri404) wants to merge 1 commit into
microsoft:mainfrom
ErfanBagheri404:fix/importHelpers-private-fields

Conversation

@ErfanBagheri404

@ErfanBagheri404 Erfan (ErfanBagheri404) commented Aug 14, 2026

Copy link
Copy Markdown

Closed

This PR targets the JavaScript-based TypeScript codebase, which is in maintenance mode. The fix has been ported to microsoft/typescript-go in PR #4841 by astegmaier.

Closing in favor of the Go-based fix.

…022+

Fixes microsoft#63728

The checkExternalEmitHelpers conditions for private identifier access
included `ClassAndClassElementDecorators` as an OR term, which is
ESNext (decorators aren't in any dated ES spec). This made the entire
condition always true for dated targets (ES2022-ES2025), incorrectly
requiring tslib for native #private field access that needs no helpers.

Remove the ClassAndClassElementDecorators and !useDefineForClassFields
terms from the three private-identifier helper-gate conditions in
checker.ts, leaving only the PrivateNamesAndClassStaticBlocks check
(ES2022).
Copilot AI lite review requested due to automatic review settings August 14, 2026 15:21
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Aug 14, 2026
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Aug 14, 2026
@ErfanBagheri404

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@RyanCavanaugh

Copy link
Copy Markdown
Member

The TypeScript repo is closed for development; PR should be in the typescript-go repo. Please see the top section of CONTRIBUTING.md and pinned issue #62963.

@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Aug 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an incorrect TS2354 (“requires an imported helper… tslib”) being reported for native #private class member usage when importHelpers: true and target >= ES2022, even though the emitter doesn’t downlevel those constructs or emit tslib helpers at those targets.

Changes:

  • Simplifies three private-identifier checkExternalEmitHelpers gate conditions in checker.ts to depend only on PrivateNamesAndClassStaticBlocks (ES2022).
  • Adds new compiler test cases for ES2022 (including static blocks and auto-accessors) and an ES2022 + useDefineForClassFields: false variant.
  • Adds baselines verifying JS output contains no tslib imports/helpers for these scenarios.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/compiler/checker.ts Removes always-true (for dated targets) helper-gating terms so ES2022+ native private members don’t spuriously require tslib.
tests/cases/compiler/importHelpersNoHelpersForPrivateFieldsAtES2022.ts New regression test covering many ES2022-native/private-member forms under importHelpers: true.
tests/cases/compiler/importHelpersNoHelpersForPrivateFieldsAtES2022UseDefineForClassFieldsFalse.ts New regression test ensuring ES2022 behavior remains correct with useDefineForClassFields: false.
tests/baselines/reference/importHelpersNoHelpersForPrivateFieldsAtES2022.js Baseline confirming no tslib import/helper usage for the ES2022 test.
tests/baselines/reference/importHelpersNoHelpersForPrivateFieldsAtES2022.types Type baseline for the ES2022 test.
tests/baselines/reference/importHelpersNoHelpersForPrivateFieldsAtES2022.symbols Symbol baseline for the ES2022 test.
tests/baselines/reference/importHelpersNoHelpersForPrivateFieldsAtES2022UseDefineForClassFieldsFalse.js Baseline confirming no tslib import/helper usage for the ES2022 + useDefineForClassFields: false test.
tests/baselines/reference/importHelpersNoHelpersForPrivateFieldsAtES2022UseDefineForClassFieldsFalse.types Type baseline for the ES2022 + useDefineForClassFields: false test.
tests/baselines/reference/importHelpersNoHelpersForPrivateFieldsAtES2022UseDefineForClassFieldsFalse.symbols Symbol baseline for the ES2022 + useDefineForClassFields: false test.
Suppressed comments (1)

src/compiler/checker.ts:34899

  • The tslib-helper check for private-field writes is still unconditional for destructuring assignments: checkReferenceAssignment calls checkExternalEmitHelpers(..., ClassPrivateFieldSet) whenever the target is a private-identifier property access, without checking languageVersion. This can still produce TS2354 at target >= ES2022 for patterns like ({ a: this.#x } = obj) even though the emitter only needs __classPrivateFieldSet when downleveling private elements (target < ES2022). Consider gating that call with the same languageVersion < LanguageFeatureMinimumTarget.PrivateNamesAndClassStaticBlocks condition, and adding a regression test that assigns into this.#field via destructuring under target: es2022 + importHelpers: true.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@typescript-automation

Copy link
Copy Markdown

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants