Repository navigation
Description
What problem does this address?
Using TypeScript function overloads prevents auto-documentation from accurately extracting function descriptions.
Example problem:
gutenberg/packages/blocks/README.md
Lines 608 to 610 in d701f12
| ### registerBlockType | |
| Undocumented declaration. |
See: https://github.com/WordPress/gutenberg/pull/77393/files#r3093041729
What is your proposed solution?
@wordpress/docgen should be updated to support extracting descriptions from common implementation patterns for function overloading.
AI-generated initial assessment:
Root cause
In
packages/docgen/lib/, TypeScript function overloads break JSDoc extraction:
JSDoc lands on the first overload signature, which babel parses as a
TSDeclareFunction(notFunctionDeclaration). See my quick AST probe above — leading comments are on overload 1, none on the implementation.
get-export-entries.js:70-93only handlesClassDeclaration/FunctionDeclaration/VariableDeclaration.TSDeclareFunctionfalls through and produces zero export entries, so the two overload signatures are silently dropped.Only the implementation (a real
FunctionDeclaration) produces an export entry. Its token has no leading comment, sogetJSDocFromTokenreturnsundefined.Fallback in
get-intermediate-representation.js:90-101(candidates = ast.body.filter(...)) also requiresFunctionDeclarationviahasNamedExportWithName/hasFunctionWithName, so it just finds the same undocumented implementation node.Result:
description ?? UNDOCUMENTED→"Undocumented declaration."atget-intermediate-representation.js:154.Is it easy?
Easy-to-medium, scoped entirely to
packages/docgen/. Fixtures live inpackages/docgen/test/and the logic is a few small files. Probably a couple of hours including tests.Technical direction
The cleanest fix is to make docgen aware that a
FunctionDeclarationexport may be preceded by siblingTSDeclareFunctionexports with the same name, and that JSDoc belongs to the first one:
get-export-entries.js: add aTSDeclareFunctioncase (treat it likeFunctionDeclarationfor naming), OR explicitly skip overload signatures so only the implementation produces an entry — your call on which.- JSDoc lookup: when processing the implementation's token and its leading comments are empty, walk backwards through
ast.bodyto find the first precedingExportNamedDeclarationwhosedeclarationis aTSDeclareFunctionwithid.name === name, and read leading comments from that token. This is the minimum change and matches how TypeScript itself associates docs with overloads.- Alternatively, relax
hasFunctionWithName/hasNamedExportWithNameto also matchTSDeclareFunctionand change thecandidates.length !== 1bailout to "use first match" — but that's more disruptive.Tests should cover: overloads with JSDoc on the first signature only, on the implementation only, and on both (first should win to match TypeScript convention).
Activity
Infinite-Null commentedon Apr 23, 2026
Hey @aduth 👋 I've opened a PR with a fix. Would love your feedback when you get a chance!
aduth commentedon Apr 27, 2026
@Infinite-Null That's great 🙌 My availability to review is pretty limited at the moment, but I'll add myself and some others to review if nobody beats me to it.