@@ -83,7 +83,7 @@ namespace ts {
8383 getShorthandAssignmentValueSymbol,
8484 getExportSpecifierLocalTargetSymbol,
8585 getTypeAtLocation: getTypeOfNode,
86- getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment ,
86+ getPropertySymbolOfDestructuringAssignment ,
8787 typeToString,
8888 getSymbolDisplayBuilder,
8989 symbolToString,
@@ -16568,6 +16568,7 @@ namespace ts {
1656816568 // [ a ] from
1656916569 // [a] = [ some array ...]
1657016570 function getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(expr: Expression): Type {
16571+ Debug.assert(expr.kind === SyntaxKind.ObjectLiteralExpression || expr.kind === SyntaxKind.ArrayLiteralExpression);
1657116572 // If this is from "for of"
1657216573 // for ( { a } of elems) {
1657316574 // }
@@ -16596,6 +16597,18 @@ namespace ts {
1659616597 indexOf((<ArrayLiteralExpression>expr.parent).elements, expr), elementType || unknownType);
1659716598 }
1659816599
16600+ // Gets the property symbol corresponding to the property in destructuring assignment
16601+ // 'property1' from
16602+ // for ( { property1: a } of elems) {
16603+ // }
16604+ // 'property1' at location 'a' from:
16605+ // [a] = [ property1, property2 ]
16606+ function getPropertySymbolOfDestructuringAssignment(location: Identifier) {
16607+ // Get the type of the object or array literal and then look for property of given name in the type
16608+ const typeOfObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(<Expression>location.parent.parent);
16609+ return typeOfObjectLiteral && getPropertyOfType(typeOfObjectLiteral, location.text);
16610+ }
16611+
1659916612 function getTypeOfExpression(expr: Expression): Type {
1660016613 if (isRightSideOfQualifiedNameOrPropertyAccess(expr)) {
1660116614 expr = <Expression>expr.parent;
0 commit comments