Functor that generates another functor that will only accept arguments with the right types based on the provided module

Hello! I need help to make two functors depend on each other, or be nested or something, and I am starting to feel stuck.
What I want to do is to create a functor (but sadly, they need to be two) to easily generate Next-Js pages.
I want the functor to ensure that what getServerSideProps returns is of the same type that what the export default expects. The problem, is that I must do those two assigns separated, because NextJs is not smart enough to remove code that is only used in getServerSideProps, so any assignment of any BE library to any intermediary variable and we are getting a import error :tm: 100% guaranteed. So I think that maybe I can make two functors, one depending on the output of the other and use the result of the second functor to generate the server side props.

This is what I had (not working):

module type PageSignature = {
  [@decco]
  type t;
  let name: string;
  let getServerSideProps:
    Next.GetServerSideProps.context => PromiseResult.t(t, string);
  let make: t => React.element;
};

module type GeneratedPage = {
  let getServerSideProps:
    Next.GetServerSideProps.context => Promise.t(Js.Json.t);
  let default: (~props: Js.Json.t) => React.element;
};

module Make = (S: PageSignature) : GeneratedPage => {
  [@decco]
  type serverProps = {props: S.t};
// ... bla bla bla

The problem is that, neither Make nor GeneratedPage should reference any module related to getServerSideProps.
I tried creating a function that gets another function and just wraps it to ensure the types match, but then the outside is not able to see the type of t and therefore it fails to type check:

type getProps('t) =
  Next.GetServerSideProps.context => PromiseResult.t('t, string);

module type PageSignature = {
  [@decco]
  type t;
  let name: string;
  let make: t => React.element;
};

module type GeneratedPage = {
  let makeGetServerSideProps:
    (getProps(t), Next.GetServerSideProps.context) => Promise.t(Js.Json.t);
  let default: (~props: Js.Json.t) => React.element;
};

module Make = (S: PageSignature) : GeneratedPage => {

Then use it like this:

module P =
  Dev__Page.Make({
    [@decco]
    type t = theReturnedType;
    let name = "Stories";
    let make = //bla bla bla react
  });

let default = P.default;
let getServerSideProps =
  P.makeGetServerSideProps( something => theReturnedType );

But, as I said, makeGetServerSideProps only accepts P.t