Skip to content
Permalink
Browse files
fix(49196): add jsdoc snippet for interface member functions (#51135)
  • Loading branch information
a-tarasyuk committed Oct 18, 2022
1 parent 7406ee9 commit f25bcb7c27d78ce89e9c9356d27058cf86dbfb5c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
@@ -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;
@@ -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));
}

@@ -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.