Redux操作的正确返回类型

问题描述 投票:1回答:1

这种类型的作品,但是由于某种原因,未定义应返回dispatch()的承诺:

enter image description here

所以不是使用ThunkAction<any,any,any,any>,还是可以使用更好的类型?也许ThunkAction完全是错误的类型?

这是我的所有代码:

import {ThunkAction, ThunkDispatch} from 'redux-thunk';
const {setLanguage} = require('redux-polyglot');
import {CMError} from '../shared/cm-error';
import {receiveCurrentUser} from './login';

export const signup = (
  email: string,
  pwd: string,
  fullName: string
): ThunkAction<any, any, any, any> => {

  return (dispatch) => {

    return fetchFromApi(`/cp/users`, {
      method: 'POST',
      body: {
        email: email,
        password: pwd,
        name: fullName
      }
    }).then(
      ([resp, json]) => {

        if (resp.status === 200) {
          return dispatch(receiveCurrentUser(json));
        }
      })
    );
  };
};

我在react-redux TS文档中没有提及此内容:https://react-redux.js.org/using-react-redux/static-typing

reactjs typescript redux react-redux tsc
1个回答
0
投票
具体针对您的情况,ThunkAction的第一个通用参数是重击程序的预期返回类型。因此,它应该类似于:
© www.soinside.com 2019 - 2024. All rights reserved.