I have a Vue application written with Typescript and I'm using Fetch to retrieve data from an api. In one of my components I have the following interface defined:
interface SearchResult {
device_id: string;
location: string;
sub_location: string;
status: string;
}
In my Fetch method I cast the response.json() promise to an array of the SearchResult interface like so:
fetch(url).then(response => response.json() as Promise<SearchResult[]>)
.then(data => {
this.results = data;
})
The issue I have is, if 'status' is not included in the response.json(), no reactive getter is created for this.results.status, meaning I can't mutate the data and have it react on the page.
I tried manually setting the value of 'status' after I the line this.results = data, and when I inspect the object using VueTools I can see it has the status property with the value I assigned it. But the reactive getter and setter is still missing.
I also tried changing the interface to a class with a constructor that set a default value for 'status', but this also failed to create the reactive getter and setter for the property.
How can I create the reactive getters and setters without explicitly adding 'status' (or any other arbitrary properties) to the api response?