Создатели действия преобразователя отправляют другого создателя действия преобразователя, но машинописный текст выдает ошибку. Какой тип мне добавить?

Как сделать так, чтобы машинописный текст не жаловался или как это исправить?

[ts] Аргумент типа '(dispatch: Dispatch) => void' не может быть назначен параметру типа PostActionTypes. В типе '(dispatch: Dispatch) => void' отсутствуют следующие свойства из типа 'GetDetailsFailAction': тип, полезная нагрузка [2345] (псевдоним) initPosts (): (dispatch: Dispatch) => void import initPosts

Какой тип мне нужно добавить при отправке действия преобразователя внутри другого действия преобразователя?

import axios from "axios";
import { initPosts } from "./init";
import { Dispatch } from "redux";
import { AppActions } from "../types/actions";

export const deletePost = (id: string) => {
  return (dispatch: Dispatch<AppActions>) => {
    axios
      .delete(`https://#####/posts/${id}`)
      .then(response => {
        if (response.status === 200) {
          dispatch(initPosts()); // error here
        }
      })
      .catch(error => {
        console.log(error);
      });
  };
};

действие initPosts

import axios from "axios";
import { AppActions } from "../types/actions";
import { IPost } from "../types/postInterface";
import { Dispatch } from "redux";

export const initPostsStart = (): AppActions => {
  return {
    type: "INIT_POSTS_START"
  };
};

export const initPostsSuccess = (allPosts: IPost[]): AppActions => {
  return {
    type: "INIT_POSTS_SUCCESS",
    payload: allPosts
  };
};

export const initPostsFail = (error: string): AppActions => {
  return {
    type: "INIT_POSTS_FAIL",
    payload: error
  };
};

export const initPosts = () => {
  return (dispatch: Dispatch<AppActions>) => {
    dispatch(initPostsStart());
    axios
      .get("https://#####/posts")
      .then(response => {
        dispatch(initPostsSuccess(response.data));
      })
      .catch(error => {
        dispatch(initPostsFail(error.message));
      });
  };
};

person True Seeker    schedule 15.11.2019    source источник


Ответы (1)


Как описано здесь,

Вы должны ввести его как,

import { ThunkAction as ReduxThunkAction } from 'redux-thunk';

type ThunkAction = ReduxThunkAction<void, IState, unknown, Action<string>>;
export const initPosts = (): ThunkAction => {
  return (dispatch) => {
    dispatch(initPostsStart());
    axios
      .get("https://#####/posts")
      .then(response => {
        dispatch(initPostsSuccess(response.data));
      })
      .catch(error => {
        dispatch(initPostsFail(error.message));
      });
  };
};

person Mike K    schedule 18.11.2020