Closed
Description
Search Terms:
spread operator, property getter
Code
interface IWhatever {
readonly value: number;
}
class Whatever implements IWhatever {
public get value() {
return 42;
}
}
const whatever: IWhatever = new Whatever();
const obj = { ...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: