Skip to content

Commit

Permalink
Infer the name of a destructured parameter
Browse files Browse the repository at this point in the history
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 TypeStrong#1703
  • Loading branch information
Gudahtt committed Sep 20, 2021
1 parent 9494412 commit 8ee3b41
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/lib/converter/plugins/CommentPlugin.ts
Expand Up @@ -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);
Expand Down

0 comments on commit 8ee3b41

Please sign in to comment.