我正在使用react-redux进行分派,并且一切正常,但是我想在axios拦截器中分派一个动作来捕获这样的错误:
axios.interceptors.response.use(null, (error) => {
const { response } = error;
const message = (response && response.data) || 'Something failed.';
store.dispatch(notificationAdd({ type: errorType, message }));
return Promise.reject(error);
});
但是流类型在store.dispatch
上引发错误:
Cannot instantiate Store because property type is read-only in object type [1]
but writable in object type [2] in type argument A.
14| ▼
[1] 15| const store: Store<State, Actions> = createStore(
16| rootReducer,
17| storeEnhancers(applyMiddleware(sagaMiddleware)),
18| );
flow-typed/npm/redux_v4.x.x.js ▼
[2] 15| declare export type Dispatch<A: { type: $Subtype<string> }> = DispatchAPI<A>;
我的通知操作如下:
type Add = $ReadOnly<{
type: typeof NOTIFICATION_ADDED,
payload: AddPayload,
}>;
export const notificationAdd = (notification: AddPayload): Add => ({
type: NOTIFICATION_ADDED,
payload: notification,
});
那么如何解决这个问题?