Closed ghost closed 3 years ago
It would be easiest to work on this issue after #344 is complete
Might be okay to not wait for that issue. We can incrementally enforce this signature on pages as it becomes feasible. And this signature might well help force #344 to get done.
Currently, we rely on developers remembering to always use ReScript types which are guaranteed to serialize to and deserialize from JSON when defining types that will be used in the return value of a
getStaticProps
method. One such type that doesn't provide guarantees is the ReScriptoption
type. Let's explicitly model the constraints that NextJS imposes ongetStaticProps
. We may also automate performing serialization and deserialization as well, but such automation is not mandatory for the first PR addressing this issue.We want to change our NextJS bindings. We want the return type of
GetStaticProps.t
to require the result of the Promise to be aJson.t
. We also want to constrain the parameter of the type passed into each NextJS page module'smake
function to be aJson.t
. Once we have these constraints in place, we need to either add a call toencode
at the end of eachgetStaticProps
implementation or make use of a functor to definegetStaticProps
given the definition of a function likegetStaticPropsImpl
which takes care of invokingencode
. Similarly, we need to perform the reverse operation as a first step in the implementation ofmake
.Note: It would be easiest to work on this issue after #344 is complete.