无法在typescript中分配导出的类实例

时间:2017-02-26 07:12:10

标签: typescript typescript2.0

我有一个模型商店类,其实例将导出如下:

<a :href="'/report/message/compose/' + student.StudentID">test</a>

稍后在我的Network模块类中解析来自axios的响应JSON:

export class CartStore {
    ...
}

export default new CartStore();

我正在使用cerialize lib来反序列化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); } CartStore

默认情况下是导出的类实例Deserialize吗?如何修复上述错误?

更新

相关答案:https://stackoverflow.com/a/32558929/510577

0 个答案:

没有答案