From 8ee3b41d4f1e5d4e07849f47cc22b7f7e5a43f31 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Mon, 20 Sep 2021 13:42:22 -0230 Subject: [PATCH] Infer the name of a destructured parameter The name of a destructured parameter can now be inferred from a JSDoc comment. The name is only inferred if the number of top-level `@param` tags in the JSDoc comment exactly matches the number of parameters. Closes #1703 --- src/lib/converter/plugins/CommentPlugin.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib/converter/plugins/CommentPlugin.ts b/src/lib/converter/plugins/CommentPlugin.ts index cb101407d..fc20f87a7 100644 --- a/src/lib/converter/plugins/CommentPlugin.ts +++ b/src/lib/converter/plugins/CommentPlugin.ts @@ -349,8 +349,21 @@ export class CommentPlugin extends ConverterComponent { childComment.tags ||= [...comment.tags]; } - signature.parameters?.forEach((parameter) => { + signature.parameters?.forEach((parameter, index) => { let tag: CommentTag | undefined; + if (childComment && parameter.name === "__namedParameters") { + const commentParams = childComment?.tags.filter( + (tag) => + tag.tagName === "param" && + !tag.paramName.includes(".") + ); + if ( + signature.parameters?.length === commentParams.length && + commentParams[index].paramName + ) { + parameter.name = commentParams[index].paramName; + } + } if (childComment) { moveNestedParamTags(childComment, parameter); tag = childComment.getTag("param", parameter.name);