@@ -182,6 +182,10 @@ namespace ts {
182182 node = getParseTreeNode(node);
183183 return node ? getTypeOfNode(node) : errorType;
184184 },
185+ getTypeOfAssignmentPattern: nodeIn => {
186+ const node = getParseTreeNode(nodeIn, isAssignmentPattern);
187+ return node && getTypeOfAssignmentPattern(node) || errorType;
188+ },
185189 getPropertySymbolOfDestructuringAssignment: locationIn => {
186190 const location = getParseTreeNode(locationIn, isIdentifier);
187191 return location ? getPropertySymbolOfDestructuringAssignment(location) : undefined;
@@ -29982,7 +29986,7 @@ namespace ts {
2998229986 // }
2998329987 // [ a ] from
2998429988 // [a] = [ some array ...]
29985- function getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment (expr: Expression ): Type {
29989+ function getTypeOfAssignmentPattern (expr: AssignmentPattern ): Type | undefined {
2998629990 Debug.assert(expr.kind === SyntaxKind.ObjectLiteralExpression || expr.kind === SyntaxKind.ArrayLiteralExpression);
2998729991 // If this is from "for of"
2998829992 // for ( { a } of elems) {
@@ -30001,17 +30005,16 @@ namespace ts {
3000130005 // for ({ skills: { primary, secondary } } = multiRobot, i = 0; i < 1; i++) {
3000230006 if (expr.parent.kind === SyntaxKind.PropertyAssignment) {
3000330007 const node = cast(expr.parent.parent, isObjectLiteralExpression);
30004- const typeOfParentObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment (node);
30008+ const typeOfParentObjectLiteral = getTypeOfAssignmentPattern (node) || errorType ;
3000530009 const propertyIndex = indexOfNode(node.properties, expr.parent);
30006- return checkObjectLiteralDestructuringPropertyAssignment(node, typeOfParentObjectLiteral || errorType , propertyIndex)!; // TODO: GH#18217
30010+ return checkObjectLiteralDestructuringPropertyAssignment(node, typeOfParentObjectLiteral, propertyIndex);
3000730011 }
3000830012 // Array literal assignment - array destructuring pattern
30009- Debug.assert (expr.parent.kind === SyntaxKind.ArrayLiteralExpression );
30013+ const node = cast (expr.parent, isArrayLiteralExpression );
3001030014 // [{ 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);
3001530018 }
3001630019
3001730020 // Gets the property symbol corresponding to the property in destructuring assignment
@@ -30022,7 +30025,7 @@ namespace ts {
3002230025 // [a] = [ property1, property2 ]
3002330026 function getPropertySymbolOfDestructuringAssignment(location: Identifier) {
3002430027 // 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) );
3002630029 return typeOfObjectLiteral && getPropertyOfType(typeOfObjectLiteral, location.escapedText);
3002730030 }
3002830031
0 commit comments