fix(55434): Renamed field takes on documentation from other field with the same name (#55469)

This commit is contained in:
Oleksandr T 2023-08-24 03:02:40 +03:00 committed by GitHub
parent 76f3f47b8b
commit daa7e985f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 100 additions and 3 deletions

View File

@ -719,11 +719,12 @@ function getSymbolDisplayPartsDocumentationAndSymbolKindWorker(typeChecker: Type
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 name = declaration.propertyName || declaration.name;
if (isIdentifier(name) && isObjectBindingPattern(parent)) {
const propertyName = getTextOfIdentifierOrLiteral(name);
const objectType = typeChecker.getTypeAtLocation(parent);
documentation = firstDefined(objectType.isUnion() ? objectType.types : [objectType], t => {
const prop = t.getProperty(name);
const prop = t.getProperty(propertyName);
return prop ? prop.getDocumentationComment(typeChecker) : undefined;
}) || emptyArray;
}

View File

@ -0,0 +1,74 @@
=== /tests/cases/fourslash/quickInfoForObjectBindingElementName06.ts ===
// type Foo = {
// /**
// * Thing is a bar
// */
// isBar: boolean
//
// /**
// * Thing is a baz
// */
// isBaz: boolean
// }
//
// function f(): Foo {
// return undefined as any
// }
//
// const { isBaz: isBar } = f();
// isBar;
// ^^^^^
// | ----------------------------------------------------------------------
// | const isBar: boolean
// | Thing is a baz
// | ----------------------------------------------------------------------
[
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoForObjectBindingElementName06.ts",
"position": 217,
"name": ""
},
"item": {
"kind": "const",
"kindModifiers": "",
"textSpan": {
"start": 212,
"length": 5
},
"displayParts": [
{
"text": "const",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "isBar",
"kind": "localName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "boolean",
"kind": "keyword"
}
],
"documentation": [
{
"text": "Thing is a baz",
"kind": "text"
}
]
}
}
]

View File

@ -0,0 +1,22 @@
/// <reference path="fourslash.ts" />
////type Foo = {
//// /**
//// * Thing is a bar
//// */
//// isBar: boolean
////
//// /**
//// * Thing is a baz
//// */
//// isBaz: boolean
////}
////
////function f(): Foo {
//// return undefined as any
////}
////
////const { isBaz: isBar } = f();
////isBar/**/;
verify.baselineQuickInfo();