Unverified Commit 72309763 authored by Ibrahem Mahyob's avatar Ibrahem Mahyob Committed by GitHub

Fix TypeScript error in with-mongodb example (#50094)

- Resolves #50084

The context parameter in the getServerSideProps function lacked a type, which led to a compile-time error. To resolve this, the GetServerSidePropsContext type from next was used to properly type the context parameter. This ensures type safety and allows TypeScript to catch potential errors at compile time.
Co-authored-by: 's avatarSteven <229881+styfle@users.noreply.github.com>
parent 815c2566
import Head from 'next/head' import Head from 'next/head'
import clientPromise from '../lib/mongodb' import clientPromise from '../lib/mongodb'
import { InferGetServerSidePropsType } from 'next' import type { InferGetServerSidePropsType, GetServerSideProps } from 'next'
export async function getServerSideProps(context) { type ConnectionStatus = {
isConnected: boolean
}
export const getServerSideProps: GetServerSideProps<
ConnectionStatus
> = async () => {
try { try {
await clientPromise await clientPromise
// `await clientPromise` will use the default database passed in the MONGODB_URI // `await clientPromise` will use the default database passed in the MONGODB_URI
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment