1

I was trying to create a common function for generating actions inside redux. I used typescript generics to restrict the type. Please see the following code and tell me if it is correct or not. Right now, it is throwing an error on the payload

The following line is throwing an error. defaultAPIAction.request())

export const createAction = <T>(type: string, error: boolean = false) =>
  (payload: T , meta: any = null): {
    type: string,
    payload?: T,
    meta?: any,
    error: boolean,
  } => ({ type, payload, meta, error });

/*
* This creates 3 constants respectively for EPIC calls only
* DEFAULT_API.REQUEST = 'form/REQUEST';
* DEFAULT_API.SUCCESS = 'form/SUCCESS';
* DEFAULT_API.FAILURE = 'form/FAILURE';
*/
export const defaultAPIAction = createApiAction(DEFAULT_API);
spender
  • 117,338
  • 33
  • 229
  • 351

0 Answers0