В reducer при использовании ...action.payLoad падает ошибка "Spread types may only be created from object types."

import {API} from "../../dal/api";
import {ThunkAction} from "redux-thunk";
import {AppStateType} from "../store";
import { UserDataPayLoadType } from "./actions_type/authActionTypes";


let SET_USER_DATA = "auth/SET_USERS";
let VALIDATE_DATA = "auth/VALIDATE_DATA";
let SET_CAPTCHA_URL = "auth/SET_CAPTCHA_URL"


let initionalState = {
    email: null as string | null,
    id: null as number | null,
    login: null as string | null,
    isAuth: false,
    validate: null as string | null,
    captchaUrl: null as string | null
}
 

export type ActionType = SetUserDataType | ValidateDataType | SetCaptchaUrlType
type InitionalStateType = typeof initionalState

export const authReducer = (state = initionalState, action: ActionType): InitionalStateType => {
    switch (action.type){
        case SET_USER_DATA:
            case VALIDATE_DATA:
                case SET_CAPTCHA_URL:
            return{
                ...state, ...action.payLoad
            }
        default:
            return state
    }
}


const setUserData = (email: string | null, id: number | null, login: string | null, isAuth: boolean): SetUserDataType => ({
    type: SET_USER_DATA,
    payLoad: {email, id, login, isAuth},
});
type SetUserDataType = {
    type:  typeof SET_USER_DATA
    payLoad: UserDataPayLoadType
}


const validateData = (validate: string): ValidateDataType => ({
    type: VALIDATE_DATA,
    payLoad: validate,
});
type ValidateDataType = {
    type: typeof VALIDATE_DATA
    payLoad: string | null
}


const setCaptchaUrl = (captcha: string): SetCaptchaUrlType => ({
    type: SET_CAPTCHA_URL,
    payLoad: captcha,
});
type SetCaptchaUrlType = {
    type: typeof SET_CAPTCHA_URL
    payLoad: string | null
}

Ответы (0 шт):