Skip to content

Fix: Exclude generator functions from convert-to-class suggestions - #62066

Closed
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-62056
Closed

Fix: Exclude generator functions from convert-to-class suggestions#62066
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-62056

Conversation

Copilot AI commented Jul 14, 2025

Copy link
Copy Markdown
Contributor

Generator functions (function*) were incorrectly triggering the TS80002 diagnostic "This constructor function may be converted to a class declaration". This is incorrect because generator functions have special semantics that are incompatible with class constructors.

Problem:

function* gen() {}
gen.prototype.next = gen.prototype.next;
gen.prototype.return = gen.prototype.return;

The above code would incorrectly trigger the convert-to-class suggestion, even though generator functions cannot be meaningfully converted to classes.

Solution:
Added checks in the canBeConvertedToClass function to exclude generator functions by testing for FunctionFlags.Generator in both function declaration and function expression paths.

Changes:

  • Modified src/services/suggestionDiagnostics.ts to exclude generator functions
  • Added comprehensive test coverage for generator declarations, generator expressions, and mixed scenarios
  • Verified that regular constructor functions continue to work correctly

Testing:

  • All existing tests pass
  • New tests verify generator functions don't trigger the diagnostic
  • Regular constructor functions still correctly trigger the diagnostic when appropriate

Fixes #62056.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits July 14, 2025 17:13
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Run npx hereby format and commit that

Copilot AI changed the title [WIP] Generator functions trigger TS80002 Fix: Exclude generator functions from convert-to-class suggestions Jul 14, 2025

Copilot AI commented Jul 14, 2025

Copy link
Copy Markdown
Contributor Author

Run npx hereby format and commit that

Ran npx hereby format - no formatting changes were needed as the code is already properly formatted.

@typescript-bot

Copy link
Copy Markdown
Contributor

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

@jakebailey
Jake Bailey (jakebailey) deleted the copilot/fix-62056 branch August 20, 2026 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generator functions trigger TS80002

3 participants