getInitialProps axios header config with TypeScript

Viewed 52

How can I satisfy TypeScript here: I have a problem here

<< headers: req?.headers >>, header type does not satisfy ts

Please see screenshot below:

enter image description here

Home.getInitialProps = async ({ req }: NextPageContext) => {
  if (typeof window === "undefined") {
  
    // we are on the server!
    const { data } = await axios.get<State>(
      "http://ingress-nginx-controller.ingress-nginx.svc.cluster.local/api/users/currentuser",
      {
        headers: req?.headers,
      }
    );

    return data;
  } 
};

Normally I have to change NextPageContext or add another type of axios?

0 Answers
Related