React 操作,ESLint:参数“dispatch”应使用非任何类型键入

pmi*_*nda 4 typescript reactjs typescript-typings

我有一个React这样的动作:

export const sigIn = () =>
  async (dispatch: any) => {
    dispatch({
      type: SIGN_IN_REQUEST
    });
  };
Run Code Online (Sandbox Code Playgroud)

我得到一个:

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

作为对 的警告async。为什么?

编辑:对于这两个答案,我输入了类型Dispatchredux但仍然有警告:

在此输入图像描述 在此输入图像描述

Nic*_*wer 5

您收到错误是因为您使用了any,并且您的 lint 规则禁止这样做。解决方法是使用正确的调度类型,可以从 redux 导入:

import { Dispatch } from 'redux';

export const sigIn = () => 
  async (dispatch: Dispatch) => {
    dispatch({
      type: SIGN_IN_REQUEST
    })
  };
Run Code Online (Sandbox Code Playgroud)