Screenshot of fetch function I am trying to fetch information from notion database in a Next.js Typescript project. So far I'm getting the error to set up type for databse_id value. How do I declare its type?
Screenshot of fetch function I am trying to fetch information from notion database in a Next.js Typescript project. So far I'm getting the error to set up type for databse_id value. How do I declare its type?
process.env.NEXT_PUBLIC_NOTION_DB returns a value of type string | undefined.
You can avoid the error either checking that it is not undefined:
export async function getStaticProps() {
if (!process.env.NEXT_PUBLIC_NOTION_DB) return { props: { }}
const res = await notion.database.query({
database_id: process.env.NEXT_PUBLIC_NOTION_DB
})
...
};
Or, providing a default value to it:
export async function getStaticProps() {
const res = await notion.database.query({
database_id: process.env.NEXT_PUBLIC_NOTION_DB || ''
})
...
};