@@ -182,6 +182,10 @@ namespace ts {
182
182
node = getParseTreeNode(node);
183
183
return node ? getTypeOfNode(node) : errorType;
184
184
},
185
+ getTypeOfAssignmentPattern: nodeIn => {
186
+ const node = getParseTreeNode(nodeIn, isAssignmentPattern);
187
+ return node && getTypeOfAssignmentPattern(node) || errorType;
188
+ },
185
189
getPropertySymbolOfDestructuringAssignment: locationIn => {
186
190
const location = getParseTreeNode(locationIn, isIdentifier);
187
191
return location ? getPropertySymbolOfDestructuringAssignment(location) : undefined;
@@ -29982,7 +29986,7 @@ namespace ts {
29982
29986
// }
29983
29987
// [ a ] from
29984
29988
// [a] = [ some array ...]
29985
- function getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment (expr: Expression ): Type {
29989
+ function getTypeOfAssignmentPattern (expr: AssignmentPattern ): Type | undefined {
29986
29990
Debug.assert(expr.kind === SyntaxKind.ObjectLiteralExpression || expr.kind === SyntaxKind.ArrayLiteralExpression);
29987
29991
// If this is from "for of"
29988
29992
// for ( { a } of elems) {
@@ -30001,17 +30005,16 @@ namespace ts {
30001
30005
// for ({ skills: { primary, secondary } } = multiRobot, i = 0; i < 1; i++) {
30002
30006
if (expr.parent.kind === SyntaxKind.PropertyAssignment) {
30003
30007
const node = cast(expr.parent.parent, isObjectLiteralExpression);
30004
- const typeOfParentObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment (node);
30008
+ const typeOfParentObjectLiteral = getTypeOfAssignmentPattern (node) || errorType ;
30005
30009
const propertyIndex = indexOfNode(node.properties, expr.parent);
30006
- return checkObjectLiteralDestructuringPropertyAssignment(node, typeOfParentObjectLiteral || errorType , propertyIndex)!; // TODO: GH#18217
30010
+ return checkObjectLiteralDestructuringPropertyAssignment(node, typeOfParentObjectLiteral, propertyIndex);
30007
30011
}
30008
30012
// Array literal assignment - array destructuring pattern
30009
- Debug.assert (expr.parent.kind === SyntaxKind.ArrayLiteralExpression );
30013
+ const node = cast (expr.parent, isArrayLiteralExpression );
30010
30014
// [{ property1: p1, property2 }] = elems;
30011
- const typeOfArrayLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(<Expression>expr.parent);
30012
- const elementType = checkIteratedTypeOrElementType(typeOfArrayLiteral || errorType, expr.parent, /*allowStringInput*/ false, /*allowAsyncIterables*/ false) || errorType;
30013
- return checkArrayLiteralDestructuringElementAssignment(<ArrayLiteralExpression>expr.parent, typeOfArrayLiteral,
30014
- (<ArrayLiteralExpression>expr.parent).elements.indexOf(expr), elementType || errorType)!; // TODO: GH#18217
30015
+ const typeOfArrayLiteral = getTypeOfAssignmentPattern(node) || errorType;
30016
+ const elementType = checkIteratedTypeOrElementType(typeOfArrayLiteral, expr.parent, /*allowStringInput*/ false, /*allowAsyncIterables*/ false) || errorType;
30017
+ return checkArrayLiteralDestructuringElementAssignment(node, typeOfArrayLiteral, node.elements.indexOf(expr), elementType);
30015
30018
}
30016
30019
30017
30020
// Gets the property symbol corresponding to the property in destructuring assignment
@@ -30022,7 +30025,7 @@ namespace ts {
30022
30025
// [a] = [ property1, property2 ]
30023
30026
function getPropertySymbolOfDestructuringAssignment(location: Identifier) {
30024
30027
// Get the type of the object or array literal and then look for property of given name in the type
30025
- const typeOfObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(<Expression> location.parent.parent);
30028
+ const typeOfObjectLiteral = getTypeOfAssignmentPattern(cast( location.parent.parent, isAssignmentPattern) );
30026
30029
return typeOfObjectLiteral && getPropertyOfType(typeOfObjectLiteral, location.escapedText);
30027
30030
}
30028
30031
0 commit comments