인프런 커뮤니티 질문&답변
typescript getServerSideProps 에러
작성
·
889
0
type script, redux toolkit으로 진행하고 있습니다.
getServerSideProps에서 type에러가 나고 있는데 검색으로도 해결이 어렵습니다. .ㅜㅜ
store설정에 문제가 있는걸까요 ..?
/pages/index.tsx
export const getServerSideProps = wrapper.getServerSideProps(
async (context: any) => {
context.store.dispatch(loadMyInfoRequest());
context.store.dispatch(loadPostRequest(undefined));
context.store.dispatch(END);
await context.store.sagaTask.toPromise();
}
);
//에러메세지
Argument of type '(context: any) => Promise<void>' is not assignable to parameter of type 'GetServerSidePropsCallback<EnhancedStore<any, AnyAction, SagaMiddleware<object>[]>, any>'.
Type 'Promise<void>' is not assignable to type 'GetServerSideProps<any, ParsedUrlQuery, PreviewData>'.
Type 'Promise<void>' provides no match for the signature '(context: GetServerSidePropsContext<ParsedUrlQuery, PreviewData>): Promise<GetServerSidePropsResult<any>>'.
/store/config.ts
import { applyMiddleware, compose, configureStore } from "@reduxjs/toolkit";
import axios from "axios";
import createSagaMiddleware from "redux-saga";
import { all, fork } from "redux-saga/effects";
import { authSaga } from "../sagas/auth.saga";
import { postSaga } from "../sagas/post.saga";
import { createWrapper } from "next-redux-wrapper";
import { composeWithDevTools } from "@reduxjs/toolkit/dist/devtoolsExtension";
import rootReducer from "../reducers";
axios.defaults.baseURL = "http://localhost:3001";
axios.defaults.withCredentials = true;
const sagaMiddleware = createSagaMiddleware();
const middlewares = [sagaMiddleware];
const enhancer =
process.env.NODE_ENV === "production"
? compose(applyMiddleware(...middlewares))
: composeWithDevTools(applyMiddleware(...middlewares));
export const store = configureStore({
reducer: rootReducer,
middleware: [sagaMiddleware],
devTools: process.env.NODE_ENV !== "production",
enhancers: [enhancer],
});
function* rootSaga() {
yield all([fork(authSaga), fork(postSaga)]);
}
sagaMiddleware.run(rootSaga);
const wrapper = createWrapper(() => store);
export default wrapper;




