@@ -14265,12 +14265,13 @@ namespace ts {
14265
14265
function checkObjectLiteralAssignment(node: ObjectLiteralExpression, sourceType: Type): Type {
14266
14266
const properties = node.properties;
14267
14267
for (const p of properties) {
14268
- checkObjectLiteralDestructuringPropertyAssignment(sourceType, p);
14268
+ checkObjectLiteralDestructuringPropertyAssignment(sourceType, p, properties );
14269
14269
}
14270
14270
return sourceType;
14271
14271
}
14272
14272
14273
- function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike) {
14273
+ /** Note: If property cannot be a SpreadAssignment, then allProperties does not need to be provided */
14274
+ function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike, allProperties?: ObjectLiteralElementLike[]) {
14274
14275
if (property.kind === SyntaxKind.PropertyAssignment || property.kind === SyntaxKind.ShorthandPropertyAssignment) {
14275
14276
const name = <PropertyName>(<PropertyAssignment>property).name;
14276
14277
if (name.kind === SyntaxKind.ComputedPropertyName) {
@@ -14300,7 +14301,14 @@ namespace ts {
14300
14301
}
14301
14302
}
14302
14303
else if (property.kind === SyntaxKind.SpreadAssignment) {
14303
- checkReferenceExpression(property.expression, Diagnostics.The_target_of_an_object_rest_assignment_must_be_a_variable_or_a_property_access);
14304
+ const nonRestNames: PropertyName[] = [];
14305
+ if (allProperties) {
14306
+ for (let i = 0; i < allProperties.length - 1; i++) {
14307
+ nonRestNames.push(allProperties[i].name);
14308
+ }
14309
+ }
14310
+ const type = getRestType(objectLiteralType, nonRestNames, objectLiteralType.symbol);
14311
+ return checkDestructuringAssignment(property.expression, type);
14304
14312
}
14305
14313
else {
14306
14314
error(property, Diagnostics.Property_assignment_expected);
@@ -14398,7 +14406,10 @@ namespace ts {
14398
14406
14399
14407
function checkReferenceAssignment(target: Expression, sourceType: Type, contextualMapper?: TypeMapper): Type {
14400
14408
const targetType = checkExpression(target, contextualMapper);
14401
- if (checkReferenceExpression(target, Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access)) {
14409
+ const error = target.parent.kind === SyntaxKind.SpreadAssignment ?
14410
+ Diagnostics.The_target_of_an_object_rest_assignment_must_be_a_variable_or_a_property_access :
14411
+ Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access;
14412
+ if (checkReferenceExpression(target, error)) {
14402
14413
checkTypeAssignableTo(sourceType, targetType, target, /*headMessage*/ undefined);
14403
14414
}
14404
14415
return sourceType;
0 commit comments