Search Terms:
spread operator, property getter
Code
interfaceIWhatever{readonlyvalue: number;}classWhateverimplementsIWhatever{publicgetvalue(){return42;}}constwhatever: IWhatever=newWhatever();constobj={ ...whatever,otherValue: 43};console.log(obj);Expected behavior:
{ value: 42, otherValue: 43 }
This is expected because a readonly property of an interface can be implemented with a getter. The code using the interface cannot know that the property is implemented with a getter and therefore expects to see the property of the interface in the result.
Actual behavior:
{ otherValue: 43 }
Playground Link:
Link
Related Issues:
Search Terms:
spread operator, property getter
Code
Expected behavior:
{ value: 42, otherValue: 43 }
This is expected because a readonly property of an interface can be implemented with a getter. The code using the interface cannot know that the property is implemented with a getter and therefore expects to see the property of the interface in the result.
Actual behavior:
{ otherValue: 43 }
Playground Link:
Link
Related Issues: