Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React action, ESLint: Argument 'dispatch' should be typed with a non-any type

I have a React action like this:

export const sigIn = () =>
  async (dispatch: any) => {
    dispatch({
      type: SIGN_IN_REQUEST
    });
  };

I'm getting a:

ESLint: Argument 'dispatch' should be typed with a non-any type.(@typescript-eslint/explicit-module-boundary-types)

as a warning on the async. Why?

Edit: for both answers, I put the Dispatch type from redux but I still have the warning:

enter image description here enter image description here

like image 799
pmiranda Avatar asked Oct 16 '25 02:10

pmiranda


1 Answers

You're getting the error because you used any, and your lint rules forbid that. The fix is to use the correct type for dispatch, which can be imported from redux:

import { Dispatch } from 'redux';

export const sigIn = () => 
  async (dispatch: Dispatch) => {
    dispatch({
      type: SIGN_IN_REQUEST
    })
  };
like image 59
Nicholas Tower Avatar answered Oct 18 '25 02:10

Nicholas Tower