Where can I grab the Typescript definitions for params and previewData? Not finding this documentation or community members talking about it here.I could use Next.js's GetStaticProps but if I do that the destructuring line const { uid, lang } = params; has errors presumably because they are from Prismic not Next.js
The second code block shows how to use GetStaticPropsContext with a typed params object.
Typing previewData
Preview data can be anything, depending on the visitor, so it may not be a good idea to type the data manually.
Instead, runtime validation should occur, where you check the object for the property you need before using it.
That being said, GetStaticPropsContext’s second type parameter allows someone to define previewData’s type.
type MyPreviewData = {
// Your data here foo: "bar"
}
type PageParams = {
uid: string
}
export function getStaticProps({ params, previewData }: GetStaticPropsContext<PageParams, MyPreviewData>) {
// ...
}
When using @prismicio/next and its enableAutoPreviews() function, you do not need to type previewData manually.
Thank you for the response and it's great the docs have been updated!! Although GetStaticPropsContext works for the previewData, take a look at the following error I get for uid and lang...