I am encountering an issue with my getter function, 'data', which returns an object. I am only able to retrieve the value since no setter has been implemented.
Despite not being able to set the value directly, I am still able to modify the data object. How can I prevent this from happening?
dataClass.ts
interface dataInterface {
test1: string;
data: object;
}
class dataModel {
private _data: dataInterface;
get data(): dataInterface {
return this._data;
}
}
externalClass.ts
class externalClass {
testData = new dataModel()
testing(){
this.testData.data.test1 = "WW"; // I can set a value even though data is meant to be read-only
this.testData.data = {test1:"WW",data:{} // This should throw an error as expected
}
}
After reviewing the code above, could you please provide guidance on how to prevent the modification of a getter object's value?
Thank you