Skip to content

Commit f25bcb7

Browse files
authoredOct 18, 2022
fix(49196): add jsdoc snippet for interface member functions (#51135)
1 parent 7406ee9 commit f25bcb7

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed
 

‎src/services/jsDoc.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,18 @@ namespace ts.JsDoc {
439439

440440
case SyntaxKind.ClassDeclaration:
441441
case SyntaxKind.InterfaceDeclaration:
442-
case SyntaxKind.PropertySignature:
443442
case SyntaxKind.EnumDeclaration:
444443
case SyntaxKind.EnumMember:
445444
case SyntaxKind.TypeAliasDeclaration:
446445
return { commentOwner };
447446

447+
case SyntaxKind.PropertySignature: {
448+
const host = commentOwner as PropertySignature;
449+
return host.type && isFunctionTypeNode(host.type)
450+
? { commentOwner, parameters: host.type.parameters, hasReturn: hasReturn(host.type, options) }
451+
: { commentOwner };
452+
}
453+
448454
case SyntaxKind.VariableStatement: {
449455
const varStatement = commentOwner as VariableStatement;
450456
const varDeclarations = varStatement.declarationList.declarations;
@@ -486,7 +492,7 @@ namespace ts.JsDoc {
486492

487493
function hasReturn(node: Node, options: DocCommentTemplateOptions | undefined) {
488494
return !!options?.generateReturnInDocTemplate &&
489-
(isArrowFunction(node) && isExpression(node.body)
495+
(isFunctionTypeNode(node) || isArrowFunction(node) && isExpression(node.body)
490496
|| isFunctionLikeDeclaration(node) && node.body && isBlock(node.body) && !!forEachReturnStatement(node.body, n => n));
491497
}
492498

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////interface I {
4+
//// /**/
5+
//// foo: (a: number, b: string) => void;
6+
////}
7+
8+
verify.docCommentTemplateAt("", 12,
9+
`/**
10+
*
11+
* @param a
12+
* @param b
13+
* @returns
14+
*/`);
15+
16+
verify.docCommentTemplateAt("", 12,
17+
`/**
18+
*
19+
* @param a
20+
* @param b
21+
*/`, { generateReturnInDocTemplate: false });

0 commit comments

Comments
 (0)
Please sign in to comment.