I have an model store class whose instance would be exported like below:
export class CartStore {
...
}
export default new CartStore();
Later in my Network module class when parsing the response JSON from axios:
import cartStore from "./CartStore"
...
export async function addToCart(timeslotId: number, quantity: number) {
return await axios.post(sprintf(Constants.ENDPOINT_ADD_TO_CART, {
"timeslot_id": timeslotId
}), { "quantity": quantity }, getConfig())
.then(res => {
let data = (res as AxiosResponse).data;
if (data != null) {
// **compilation error** below saying that "cannot assign to 'cartStore' because it is not a variable"
cartStore = Deserialize(data, CartStore); // <--
...
} else {
console.warn("[NetworkManager]", `null response when addToCart with timeslot id: ${timeslotId}`);
}
})
.catch(defaultErrorHandler);
}
I am using cerialize
lib for deserializing my CartStore
through Deserialize
.
Is it the class instance being exported readonly
by default? How to fix the above error?
UPDATE
Related answer: https://stackoverflow.com/a/32558929/510577