diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index 6d453d135ef..0524d150972 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -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; } diff --git a/tests/baselines/reference/quickInfoForObjectBindingElementName06.baseline b/tests/baselines/reference/quickInfoForObjectBindingElementName06.baseline new file mode 100644 index 00000000000..33ed9bf843e --- /dev/null +++ b/tests/baselines/reference/quickInfoForObjectBindingElementName06.baseline @@ -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" + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoForObjectBindingElementName06.ts b/tests/cases/fourslash/quickInfoForObjectBindingElementName06.ts new file mode 100644 index 00000000000..5bc263cc1aa --- /dev/null +++ b/tests/cases/fourslash/quickInfoForObjectBindingElementName06.ts @@ -0,0 +1,22 @@ +/// + +////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();