fix(declarations): keep JSDoc @typedef/@callback comments with their type - #64180
Open
Eugene Kalinin (ekalinin) wants to merge 3 commits into
Open
fix(declarations): keep JSDoc @typedef/@callback comments with their type#64180Eugene Kalinin (ekalinin) wants to merge 3 commits into
Eugene Kalinin (ekalinin) wants to merge 3 commits into
Conversation
… type Declarations reparsed from a JSDoc `@typedef`/`@callback` take the text range of the tag they came from, which sits inside the comment. The printer finds no leading comment there and the comment is instead swept up by the next statement's leading comment scan, so the type is emitted undocumented while an unrelated declaration gets its docs. Add comment ownership to EmitContext: a claimed comment is emitted by its owner and skipped by every other node scanning across it, and the owner emits nothing but the comment it claimed. The declaration transformer claims a JSDoc comment for the first declaration reparsed out of it when every tag in the comment is one that reparses into a declaration of its own. Fixes microsoft#63958
Copilot started reviewing on behalf of
Eugene Kalinin (ekalinin)
September 5, 2026 11:50
View session
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Two moderate comment-ownership gaps remain for generic aliases and standalone @import declarations.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Introduces comment ownership so JSDoc @typedef and @callback documentation remains attached to generated declarations.
Changes:
- Adds ownership tracking and printer filtering for claimed comments.
- Claims eligible JSDoc comments during declaration transformation.
- Adds placement tests and updates affected baselines.
Review findings:
- Moderate (1 vote):
transform.go:477excludes@templatefrom declaration-only blocks, leaving generic@typedef/@callbackaliases separated from their documentation. - Moderate (1 vote):
transform.go:507cannot claim standalone@importcomments because reparsed imports lack JSDoc metadata; this path needs correction and standalone regression coverage.
File summaries
| File | Description |
|---|---|
tsc/testdata/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypedefCommentPlacement.ts |
Adds comment-placement scenarios. |
tsc/testdata/baselines/reference/tsbuild/javascriptProjectEmit/loads-js-based-projects-and-emits-them-correctly.js |
Updates build output. |
tsc/testdata/baselines/reference/conformance/typedefOnStatements.js |
Preserves comments from elided statements. |
tsc/testdata/baselines/reference/conformance/typedefOnSemicolonClassElement.js |
Preserves a class-element typedef comment. |
tsc/testdata/baselines/reference/conformance/typedefModuleExportsIndirect3.js |
Repositions typedef comments. |
tsc/testdata/baselines/reference/conformance/typedefModuleExportsIndirect2.js |
Repositions typedef comments. |
tsc/testdata/baselines/reference/conformance/typedefModuleExportsIndirect1.js |
Repositions typedef comments. |
tsc/testdata/baselines/reference/conformance/templateInsideCallback.js |
Updates callback/type comment placement. |
tsc/testdata/baselines/reference/conformance/recursiveTypeReferences2.js |
Associates recursive-type comments. |
tsc/testdata/baselines/reference/conformance/linkTagEmit1.js |
Associates linked typedef comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsUniqueSymbolUsage.js |
Repositions typedef documentation. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsTypedefPropertyAndExportAssignment.js |
Associates exported type comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsTypedefDescriptionsPreserved.js |
Preserves description placement. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsTypedefCommentPlacement.types |
Adds the type baseline. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsTypedefCommentPlacement.symbols |
Adds the symbol baseline. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsTypedefCommentPlacement.js |
Adds the emit baseline. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsTypedefAndImportTypes.js |
Updates import-related comment placement. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsTypeAliases.js |
Updates type-alias comment placement. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js |
Repositions callback/type comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsImportNamespacedType.js |
Moves documentation into the generated namespace. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js |
Associates namespace alias comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsImportAliasExposedWithinNamespace.js |
Associates namespace alias comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsFunctionPrototypeStatic(target=es2015).js |
Repositions callback documentation. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsFunctionClassesCjsExportAssignment(target=es2015).js |
Associates generated type comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsDefaultsErr(target=es2015).js |
Repositions default alias comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsDefault(target=es2015).js |
Repositions default alias comments. |
tsc/testdata/baselines/reference/conformance/jsDeclarationsClassStatic(target=es2015).js |
Associates options documentation. |
tsc/testdata/baselines/reference/conformance/checkJsdocSatisfiesTag15.js |
Repositions typedef documentation. |
tsc/testdata/baselines/reference/conformance/callbackOnConstructor.js |
Moves callback documentation to its alias. |
tsc/testdata/baselines/reference/compiler/typedefHoisting.js |
Associates hoisted typedef comments. |
tsc/testdata/baselines/reference/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.js |
Repositions typedef documentation. |
tsc/testdata/baselines/reference/compiler/jsTypedefMergedWithModuleExportProperty.js |
Associates merged typedef comments. |
tsc/testdata/baselines/reference/compiler/jsdocNonIdentifierPropertiesAndParams.js |
Repositions callback documentation. |
tsc/testdata/baselines/reference/compiler/jsdocMultilineUnion.js |
Associates a multiline typedef comment. |
tsc/testdata/baselines/reference/compiler/jsDocCallbackExport2.js |
Repositions exported callback documentation. |
tsc/testdata/baselines/reference/compiler/jsDocCallbackExport1.js |
Repositions callback documentation. |
tsc/testdata/baselines/reference/compiler/jsDeclarationsInheritedTypes.js |
Associates inherited-type documentation. |
tsc/testdata/baselines/reference/compiler/jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.js |
Moves typedef documentation to the exported alias. |
tsc/testdata/baselines/reference/compiler/jsDeclarationEmitDoesNotRenameImport.js |
Associates options typedef documentation. |
tsc/testdata/baselines/reference/compiler/exportAssignmentMerging6.js |
Repositions merged typedef comments. |
tsc/testdata/baselines/reference/compiler/exportAssignmentMerging5.js |
Repositions merged typedef comments. |
tsc/internal/transformers/declarations/transform.go |
Claims JSDoc comments for reparsed declarations. |
tsc/internal/printer/printer.go |
Restricts claimed-comment emission to owners. |
tsc/internal/printer/emitcontext.go |
Tracks claimed-comment ownership. |
Review details
- Files reviewed: 44/44 changed files
- Comments generated: 2
- Review effort level: Balanced
…verload Review follow-up on the reparsed-JSDoc comment ownership. `@template` was rejected by the tag predicate, so a generic alias declared with `@template` + `@typedef`/`@callback` still lost its comment. The parser hands every `@template` in such a comment to the type being declared and leaves none for the host (gatherTypeParameters), so mirror that: a template tag is unhosted exactly when its comment also declares a type. `@import` and `@overload` were listed as claimable but could never claim, because reparseUnhosted recorded no JSDocInfo for the declarations it builds from them and their JSDoc lookup was always empty. Register the comment the way the typedef and callback cases already do. This also gives overload signatures their documentation in signature help, which was previously dropped. Stop the detached-comment run at a claimed comment. Its owner is emitted later, so detaching the rest of the run printed those comments ahead of the owner and put them out of source order.
Copilot started reviewing on behalf of
Jake Bailey (jakebailey)
September 5, 2026 19:26
View session
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A critical diagnostic regression and three unresolved comment-ownership issues must be fixed.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
tsc/internal/transformers/declarations/transform.go:522
- For a block containing both
@importand@typedef, the generated import appears first and wins the claim, so the typedef comment is still not attached to its type. The newimported.d.tsbaseline places “Imports and defines in one comment” beforeimport type { Point }, leavingPathwith no JSDoc and therefore no type hover documentation. Prefer the typedef/callback declaration as owner when a block also generates imports, or attach the relevant documentation to each declared type.
if loc, ok := tx.commentRangeOfJSDoc(jsdoc, file); ok {
tx.EmitContext().ClaimComment(statement, jsdoc.Pos(), loc)
- Files reviewed: 55/55 changed files
- Comments generated: 3
- Review effort level: Balanced
…ents Review follow-up. Registering the containing JSDoc on a reparsed overload signature fed the whole block to the checker as that signature's JSDoc, so checkUnmatchedJSDocParameters validated the implementation's own `@param` tags against it and reported TS8024 for parameters that do exist. Overload documentation was never emitted before this branch, so drop the registration rather than narrow it; scoping a comment to a single `@overload` tag is a change of its own. Invert the tag predicate. Instead of listing the tags that may be claimed, a comment is claimed when it declares something and carries no tag that documents another node - the ones the parser applies to the host, per reparseHosted, plus `@overload`. Everything left over, a description or `@see` or `@example`, describes what the comment declares, so a `@typedef` beside a `@see` no longer leaves its comment behind. Claim over the statements as they enter the late-painted pass rather than over its output. A comment whose declaration is elided is then claimed by nothing and drops with it, instead of being swept onto the next declaration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #63958
A JSDoc
@typedef/@callbackpreceded by another top-level declaration loses its comment to the next statement: