@piccca
Котэ

Ошибка typescript при импортировании actions redux?

Я делаю в одиночку большое приложение react+redux и столкнулся со странной ошибкой! Прошу профи помочь.
Вот код из Profile.reducer.ts:
export const actions = {
  setAuthUserData: (userid: number | null, login: string | null,
    profile: profileType | null, isAuth: boolean) => ({
    type: SET_AUTH_DATA,
    data: { userid, login, profile, isAuth }
  } as const),
  setAuthProfile: (profile: SaveProfileFormValues) => ({
    type: SET_AUTH_PROFILE, profile
  } as const),
  toggleIsFetching: (isFetching: boolean) => ({
    type: TOGGLE_IS_FETCHING, isFetching
  } as const)
}

Так у меня приложении создаются actions чтобы было мало кода.
Из Profile.reducer.ts я вызываю данный код:
import { actions as authActions } from '../redux/Auth.reducer'
type ActionTypes = InferActionsTypes<typeof actions>
type ThunkType = AppThunk<ActionTypes>
export const saveProfile = (profile: SaveProfileFormValues): ThunkType =>
  async (dispatch) => {
    const data = await profileAPI.save(profile)
    if(data.resultCode === ResultCodes.Success) {
      dispatch(actions.saveProfileSuccess(profile))
      dispatch(authActions.setAuthProfile(profile))
    }
  }

В итоге после на диспатче authActions выходит огромная ошибка:
Failed to compile.

/home/admin/app/src/redux/Profile.reducer.ts
TypeScript error in /home/admin/app/src/redux/Profile.reducer.ts(173,16):
No overload matches this call.
  Overload 1 of 2, '(action: { readonly type: "react-social-network/profile/ADD-POST"; readonly post: postType; } | { readonly type: "react-social-network/profile/SET_USER_PROFILE"; readonly profile: Nullable<profileType>; } | ... 6 more ... | { ...; }): { ...; } | ... 7 more ... | { ...; }', gave the following error.
    Argument of type '{ readonly type: "react-social-network/auth/SET_AUTH_PROFILE"; readonly profile: SaveProfileFormValues; }' is not assignable to parameter of type '{ readonly type: "react-social-network/profile/ADD-POST"; readonly post: postType; } | { readonly type: "react-social-network/profile/SET_USER_PROFILE"; readonly profile: Nullable<profileType>; } | ... 6 more ... | { ...; }'.
      Type '{ readonly type: "react-social-network/auth/SET_AUTH_PROFILE"; readonly profile: SaveProfileFormValues; }' is not assignable to type '{ readonly type: "react-social-network/profile/SAVE_PHOTO_SUCCESS"; readonly profile: SaveProfileFormValues; }'.
        Types of property 'type' are incompatible.
          Type '"react-social-network/auth/SET_AUTH_PROFILE"' is not assignable to type '"react-social-network/profile/SAVE_PHOTO_SUCCESS"'.
  Overload 2 of 2, '(asyncAction: ThunkAction<unknown, CombinedState<{ app: { initialized: boolean; }; auth: { userid: Nullable<number>; login: Nullable<string>; profile: Nullable<profileType>; isAuth: boolean; isFetching: boolean; }; ... 4 more ...; form: FormStateMap; }>, unknown, { ...; } | ... 7 more ... | { ...; }>): unknown', gave the following error.
    Argument of type '{ readonly type: "react-social-network/auth/SET_AUTH_PROFILE"; readonly profile: SaveProfileFormValues; }' is not assignable to parameter of type 'ThunkAction<unknown, CombinedState<{ app: { initialized: boolean; }; auth: { userid: Nullable<number>; login: Nullable<string>; profile: Nullable<profileType>; isAuth: boolean; isFetching: boolean; }; ... 4 more ...; form: FormStateMap; }>, unknown, { ...; } | ... 7 more ... | { ...; }>'.
      Type '{ readonly type: "react-social-network/auth/SET_AUTH_PROFILE"; readonly profile: SaveProfileFormValues; }' provides no match for the signature '(dispatch: ThunkDispatch<CombinedState<{ app: { initialized: boolean; }; auth: { userid: Nullable<number>; login: Nullable<string>; profile: Nullable<profileType>; isAuth: boolean; isFetching: boolean; }; ... 4 more ...; form: FormStateMap; }>, unknown, { ...; } | ... 7 more ... | { ...; }>, getState: () => CombinedState<...>, extraArgument: unknown): unknown'.  TS2769

    171 |     if(data.resultCode === ResultCodes.Success) {
    172 |       dispatch(actions.saveProfileSuccess(profile))
  > 173 |       dispatch(authActions.setAuthProfile(profile))
        |                ^
    174 |     }
    175 |   }
    176 |

Насколько я понял это связано с ThunkType, но если импортировать ActionsTypes и совместить его то появляется ещё больше ошибок. Помогите решить
  • Вопрос задан
  • 34 просмотра
Пригласить эксперта
Ваш ответ на вопрос

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

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