Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(49196): The '/ * *' snippet should support parameter deconstruction of typescript interface member functions #51135

Merged
merged 1 commit into from Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 });