Within my TypeScript class, I have a skip
function. In the interface
, I've specified that the data is coming from the backend.
Now, on the frontend
, I want to be able to rename the backend variables
as demonstrated below. There are multiple variables and I'm seeking ways to optimize the code efficiently.
I contemplated using the Destructuring concept but I'm uncertain about how to implement it. Any assistance would be greatly appreciated.
this.recordId = data?.data1;
this.oldValue = data?.data2;
this.newValue = data?.data3;
............// many more
The TypeScript function:
skip(rec: ABC) {
const { data1, data2, data3 } = rec;
this.records.skip({ data1, data2, data3}).subscribe(data => {
this.recordId = data?.data1;
this.oldValue = data?.data2;
this.newValue = data?.data3;
............// many more
this.processIncomingRecord(data);
});
}
rec.ts
export interface ABC {
data1: number;
data2: number;
data3: number;
}