Next.js - Infer SSR Props

type GetSSRResult<TProps> =
  | { props: TProps }
  | { redirect: any }
  | { notFound: boolean };

type GetSSRFn<TProps> = (args: any) => Promise<GetSSRResult<TProps>>;

export type inferSSRProps<TFn extends GetSSRFn<any>> = TFn extends GetSSRFn<infer TProps>
  ? NonNullable<TProps>
  : never;

const Members: NextPageWithLayout<inferSSRProps<typeof getServerSideProps>> = ({
  posts,
}) => {
  return <></>
}

export const getServerSideProps = async (
  context: GetServerSidePropsContext
) => {
  const posts = await prisma.post.findMany()

  return {
    props: {
      posts,
    },
  }
}

export default Members

Source