If you're using VS Code, you have the option to simply right click on a type and select "Go to Definition". The definition for the GetServerSideProps
type is specified within next.js as follows:
export type GetServerSideProps<
P extends { [key: string]: any } = { [key: string]: any },
Q extends ParsedUrlQuery = ParsedUrlQuery,
D extends PreviewData = PreviewData
> = (
context: GetServerSidePropsContext<Q, D>
) => Promise<GetServerSidePropsResult<P>>
From this, it is evident that the context
parameter is of type GetServerSidePropsContext
, with certain generic parameters.
Therefore, your function can be modified as shown below:
import type {
GetServerSideProps,
GetServerSidePropsContext,
PreviewData,
} from "next";
import { ParsedUrlQuery } from "querystring";
// ...
export function getMovies<Q extends ParsedUrlQuery, D extends PreviewData>(
context: GetServerSidePropsContext<Q, D>,
req: GetServerSidePropsContext<Q, D>["req"]
) {
// ...
}
Consider omitting the req
parameter, as it is already included in the context
. If necessary, you can extract it within the getMovies
function.