@@ -83,7 +83,7 @@ namespace ts {
83
83
getShorthandAssignmentValueSymbol,
84
84
getExportSpecifierLocalTargetSymbol,
85
85
getTypeAtLocation: getTypeOfNode,
86
- getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment ,
86
+ getPropertySymbolOfDestructuringAssignment ,
87
87
typeToString,
88
88
getSymbolDisplayBuilder,
89
89
symbolToString,
@@ -16568,6 +16568,7 @@ namespace ts {
16568
16568
// [ a ] from
16569
16569
// [a] = [ some array ...]
16570
16570
function getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(expr: Expression): Type {
16571
+ Debug.assert(expr.kind === SyntaxKind.ObjectLiteralExpression || expr.kind === SyntaxKind.ArrayLiteralExpression);
16571
16572
// If this is from "for of"
16572
16573
// for ( { a } of elems) {
16573
16574
// }
@@ -16596,6 +16597,18 @@ namespace ts {
16596
16597
indexOf((<ArrayLiteralExpression>expr.parent).elements, expr), elementType || unknownType);
16597
16598
}
16598
16599
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
+
16599
16612
function getTypeOfExpression(expr: Expression): Type {
16600
16613
if (isRightSideOfQualifiedNameOrPropertyAccess(expr)) {
16601
16614
expr = <Expression>expr.parent;
0 commit comments