Port TypeScript PR #59675: fix(59397): JSDoc is missing/duplicated in declarations for overloads declared in classes declared in functions #1130
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR ports the fix from TypeScript PR #59675 to resolve an issue where JSDoc comments were missing or duplicated in declarations for overloads declared in classes declared in functions.
Problem
When generating type declarations for method overloads in classes that are declared within functions, all overloads would incorrectly share the same JSDoc comment instead of preserving their individual comments.
Consider this TypeScript code:
Before this fix: The generated
.d.tsfile would show both overloads with "comment 1"After this fix: Each overload correctly preserves its own JSDoc comment
Solution
Updated the comment range logic in
addPropertyToElementList()ininternal/checker/nodebuilderimpl.goto prioritize signature-specific declarations over property symbol declarations for method overloads:This ensures that each overload signature gets its correct JSDoc comment instead of all overloads sharing the same comment from the property symbol.
Testing
The fix is validated by the
signatureOverloadsWithComments.tstest case (imported from the TypeScript submodule), which now correctly generates declarations with preserved individual JSDoc comments for each overload.Fixes #1126.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.