Reactjs 反应动作,ESLint:Argument';调度';应使用非任何类型的
我有一个Reactjs 反应动作,ESLint:Argument';调度';应使用非任何类型的,reactjs,typescript,typescript-typings,Reactjs,Typescript,Typescript Typings,我有一个反应动作如下: export const sigIn = () => async (dispatch: any) => { dispatch({ type: SIGN_IN_REQUEST }); }; 我得到一个: ESLint: Argument 'dispatch' should be typed with a non-any type.(@typescript-eslint/explicit-module-boundary-typ
反应
动作如下:
export const sigIn = () =>
async (dispatch: any) => {
dispatch({
type: SIGN_IN_REQUEST
});
};
我得到一个:
ESLint: Argument 'dispatch' should be typed with a non-any type.(@typescript-eslint/explicit-module-boundary-types)
作为async
上的警告。为什么?
编辑:对于这两个答案,我从redux
中输入Dispatch
类型,但仍然有警告:
您之所以会出现错误,是因为您使用了
any
,而您的lint规则禁止这样做。修复方法是使用正确的分派类型,可以从redux导入:
import { Dispatch } from 'redux';
export const sigIn = () =>
async (dispatch: Dispatch) => {
dispatch({
type: SIGN_IN_REQUEST
})
};
您可以在eslint配置中禁用该规则,也可以添加足够的类型
import { Dispatch } from 'react-redux';
async (dispatch: Dispatch<{ type: SIGN_IN_REQUEST }>): void => {
dispatch({
type: SIGN_IN_REQUEST
});
从'react redux'导入{Dispatch};
异步(分派:分派):void=>{
派遣({
类型:登录请求
});
@pmiranda然后在末尾添加一个void
,因为它不返回任何内容。修复函数中缺少返回类型的方法是向函数中添加一个返回类型。看起来它应该是Promise
。是的,Promive
有效,谢谢。我会选择正确的答案,因为这是第一个答案