Skip to content

Commit

Permalink
fix(49196): add jsdoc snippet for interface member functions (#51135)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk committed Oct 18, 2022
1 parent 7406ee9 commit f25bcb7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/services/jsDoc.ts
Expand Up @@ -439,12 +439,18 @@ namespace ts.JsDoc {

case SyntaxKind.ClassDeclaration:
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.PropertySignature:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.EnumMember:
case SyntaxKind.TypeAliasDeclaration:
return { commentOwner };

case SyntaxKind.PropertySignature: {
const host = commentOwner as PropertySignature;
return host.type && isFunctionTypeNode(host.type)
? { commentOwner, parameters: host.type.parameters, hasReturn: hasReturn(host.type, options) }
: { commentOwner };
}

case SyntaxKind.VariableStatement: {
const varStatement = commentOwner as VariableStatement;
const varDeclarations = varStatement.declarationList.declarations;
Expand Down Expand Up @@ -486,7 +492,7 @@ namespace ts.JsDoc {

function hasReturn(node: Node, options: DocCommentTemplateOptions | undefined) {
return !!options?.generateReturnInDocTemplate &&
(isArrowFunction(node) && isExpression(node.body)
(isFunctionTypeNode(node) || isArrowFunction(node) && isExpression(node.body)
|| isFunctionLikeDeclaration(node) && node.body && isBlock(node.body) && !!forEachReturnStatement(node.body, n => n));
}

Expand Down
@@ -0,0 +1,21 @@
/// <reference path="fourslash.ts" />

////interface I {
//// /**/
//// foo: (a: number, b: string) => void;
////}

verify.docCommentTemplateAt("", 12,
`/**
*
* @param a
* @param b
* @returns
*/`);

verify.docCommentTemplateAt("", 12,
`/**
*
* @param a
* @param b
*/`, { generateReturnInDocTemplate: false });

0 comments on commit f25bcb7

Please sign in to comment.