@@ -14188,12 +14188,13 @@ namespace ts {
14188
14188
function checkObjectLiteralAssignment(node: ObjectLiteralExpression, sourceType: Type): Type {
14189
14189
const properties = node.properties;
14190
14190
for (const p of properties) {
14191
- checkObjectLiteralDestructuringPropertyAssignment(sourceType, p);
14191
+ checkObjectLiteralDestructuringPropertyAssignment(sourceType, p, properties );
14192
14192
}
14193
14193
return sourceType;
14194
14194
}
14195
14195
14196
- function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike) {
14196
+ /** Note: If property cannot be a SpreadAssignment, then allProperties does not need to be provided */
14197
+ function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike, allProperties?: ObjectLiteralElementLike[]) {
14197
14198
if (property.kind === SyntaxKind.PropertyAssignment || property.kind === SyntaxKind.ShorthandPropertyAssignment) {
14198
14199
const name = <PropertyName>(<PropertyAssignment>property).name;
14199
14200
if (name.kind === SyntaxKind.ComputedPropertyName) {
@@ -14223,7 +14224,14 @@ namespace ts {
14223
14224
}
14224
14225
}
14225
14226
else if (property.kind === SyntaxKind.SpreadAssignment) {
14226
- checkReferenceExpression(property.expression, Diagnostics.The_target_of_an_object_rest_assignment_must_be_a_variable_or_a_property_access);
14227
+ const nonRestNames: PropertyName[] = [];
14228
+ if (allProperties) {
14229
+ for (let i = 0; i < allProperties.length - 1; i++) {
14230
+ nonRestNames.push(allProperties[i].name);
14231
+ }
14232
+ }
14233
+ const type = getRestType(objectLiteralType, nonRestNames, objectLiteralType.symbol);
14234
+ return checkDestructuringAssignment(property.expression, type);
14227
14235
}
14228
14236
else {
14229
14237
error(property, Diagnostics.Property_assignment_expected);
@@ -14321,7 +14329,10 @@ namespace ts {
14321
14329
14322
14330
function checkReferenceAssignment(target: Expression, sourceType: Type, contextualMapper?: TypeMapper): Type {
14323
14331
const targetType = checkExpression(target, contextualMapper);
14324
- if (checkReferenceExpression(target, Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access)) {
14332
+ const error = target.parent.kind === SyntaxKind.SpreadAssignment ?
14333
+ Diagnostics.The_target_of_an_object_rest_assignment_must_be_a_variable_or_a_property_access :
14334
+ Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access;
14335
+ if (checkReferenceExpression(target, error)) {
14325
14336
checkTypeAssignableTo(sourceType, targetType, target, /*headMessage*/ undefined);
14326
14337
}
14327
14338
return sourceType;
0 commit comments