mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Get quickInfo from a contextual type if possible (#18119)
This commit is contained in:
@@ -1398,7 +1398,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
const typeChecker = program.getTypeChecker();
|
||||
const symbol = typeChecker.getSymbolAtLocation(node);
|
||||
const symbol = getSymbolAtLocationForQuickInfo(node, typeChecker);
|
||||
|
||||
if (!symbol || typeChecker.isUnknownSymbol(symbol)) {
|
||||
// Try getting just type at this position and show
|
||||
@@ -1437,6 +1437,21 @@ namespace ts {
|
||||
};
|
||||
}
|
||||
|
||||
function getSymbolAtLocationForQuickInfo(node: Node, checker: TypeChecker): Symbol | undefined {
|
||||
if ((isIdentifier(node) || isStringLiteral(node))
|
||||
&& isPropertyAssignment(node.parent)
|
||||
&& node.parent.name === node) {
|
||||
const type = checker.getContextualType(node.parent.parent);
|
||||
if (type) {
|
||||
const property = checker.getPropertyOfType(type, getTextOfIdentifierOrLiteral(node));
|
||||
if (property) {
|
||||
return property;
|
||||
}
|
||||
}
|
||||
}
|
||||
return checker.getSymbolAtLocation(node);
|
||||
}
|
||||
|
||||
/// Goto definition
|
||||
function getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[] {
|
||||
synchronizeHostData();
|
||||
|
||||
Reference in New Issue
Block a user