@jenya7771

Почему в React, Redux в mapDispatchToProps не могу указать в generic свой тип actions?

Здравствуйте, подскажите пожалуйста, почему возникает вот такая ошибка:
TS2769: No overload matches this call.   The last overload gave the following error.     Argument of type 'Dispatch<UserActions>' is not assignable to parameter of type 'Dispatch<AnyAction>'.       Type 'AnyAction' is not assignable to type 'UserActions'.         Property 'payload' is missing in type 'AnyAction' but required in type 'UserLoginErrorAction'.


Вот подробнее код:
6187d605af6ad809170712.png

Все что касается actions:
import { Action } from 'redux';

export enum UserTypes {
    USER_LOGIN_REQUEST = 'USER_LOGIN_REQUEST',
    USER_LOGIN_SUCCESS = 'USER_LOGIN_SUCCESS',
    USER_LOGIN_ERROR = 'USER_LOGIN_ERROR',
}

export interface UserState {
    error: any,
    loading: boolean,
    currentUser: {
        id: string,
        email: string,
        role: string,
        balance: number
    } | undefined
}

export interface UserLoginRequestPayload {
    username: string,
    password: string
}

export interface UserLoginSuccessPayload {
    id: string,
    email: string,
    role: string,
    balance: number
}

export interface UserLoginRequestAction extends Action {
    type: UserTypes.USER_LOGIN_REQUEST,
    payload: UserLoginRequestPayload
}

export interface UserLoginSuccessAction extends Action {
    type: UserTypes.USER_LOGIN_SUCCESS,
    payload: UserLoginSuccessPayload
}

export interface UserLoginErrorAction extends Action  {
    type: UserTypes.USER_LOGIN_ERROR
    payload: any
}

export type UserActions = UserLoginRequestAction | UserLoginSuccessAction | UserLoginErrorAction


Все что касается actionCreators:
export function loginUserRequestActionCreator(payload: UserLoginRequestPayload): UserLoginRequestAction {
    return {
        type: UserTypes.USER_LOGIN_REQUEST,
        payload
    }
}

export function loginUserSuccessActionCreator(payload: UserLoginSuccessPayload): UserLoginSuccessAction {
    return {
        type: UserTypes.USER_LOGIN_SUCCESS,
        payload
    }
}

export function loginUserErrorActionCreator(payload: any): UserLoginErrorAction {
    return {
        type: UserTypes.USER_LOGIN_ERROR,
        payload: payload
    }
}
  • Вопрос задан
  • 79 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы