0

Im using next-redux-wrapper and I get following 2 type errors. Anyone encounter this before and how do you solve it? All else, the code is working and i can see my state in my redux-devtools-extension. Thanks

import { useSelector } from "react-redux";

import Layout from "../components/Layout";
import { getProjects } from "../redux/actions/projectActions";
import { wrapper } from "../redux/store";

const Redux = () => {

// Warning 1: Property 'allProjects' does not exist on type 'DefaultRootState'.ts(2339)

  const { projects } = useSelector((state) => state.allProjects);
  console.log("res", projects);

  return (
    <Layout>
      <h1>Redux</h1>
    </Layout>
  );
};

export const getServerSideProps = 

// Warning 2: Type '({ req }: GetServerSidePropsContext<ParsedUrlQuery>) => Promise<void>' is not assignable to type 'GetServerSideProps<any, ParsedUrlQuery>'.
  Type 'Promise<void>' is not assignable to type 'Promise<GetServerSidePropsResult<any>>'.
    Type 'void' is not assignable to type 'GetServerSidePropsResult<any>'.ts(2322)

wrapper.getServerSideProps(
  (store) =>
    async ({ req }) => {
      (await store.dispatch(getProjects(req))) as any;
    }
);

export default Redux;


Hendry Lim
  • 1,929
  • 2
  • 21
  • 45

1 Answers1

0

I did below and the ts warnings went away

I m not sure if it's correct though but so far seems ok

import { RootStateOrAny, useSelector } from "react-redux";

import Layout from "../components/Layout";
import { getProjects } from "../redux/actions/projectActions";
import { wrapper } from "../redux/store";

const Redux = () => {
  const { projects } = useSelector(
    (state: RootStateOrAny) => state.allProjects
  );
  console.log("res", projects);

  return (
    <Layout>
      <h1>Redux</h1>
    </Layout>
  );
};

export const getServerSideProps = wrapper.getServerSideProps(
  (store) =>
    async ({ req }) => {
      await store.dispatch(getProjects(req));
      return {
        props: {},
      };
    }
);

export default Redux;
Hendry Lim
  • 1,929
  • 2
  • 21
  • 45