feat(27601): include JSDoc comments for destructuring arguments (#46886)

This commit is contained in:
Oleksandr T
2022-02-03 21:27:40 +02:00
committed by GitHub
parent 46d1cb11e2
commit 0d5abd8a15
7 changed files with 342 additions and 0 deletions

View File

@@ -584,6 +584,19 @@ namespace ts.SymbolDisplay {
}
}
if (documentation.length === 0 && isIdentifier(location) && symbol.valueDeclaration && isBindingElement(symbol.valueDeclaration)) {
const declaration = symbol.valueDeclaration;
const parent = declaration.parent;
if (isIdentifier(declaration.name) && isObjectBindingPattern(parent)) {
const name = getTextOfIdentifierOrLiteral(declaration.name);
const objectType = typeChecker.getTypeAtLocation(parent);
documentation = firstDefined(objectType.isUnion() ? objectType.types : [objectType], t => {
const prop = t.getProperty(name);
return prop ? prop.getDocumentationComment(typeChecker) : undefined;
}) || emptyArray;
}
}
if (tags.length === 0 && !hasMultipleSignatures) {
tags = symbol.getContextualJsDocTags(enclosingDeclaration, typeChecker);
}