Skip to content

Commit

Permalink
Fix TypeScript error in with-mongodb example (#50094)
Browse files Browse the repository at this point in the history
- 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: Steven <[email protected]>
  • Loading branch information
ibrahemid and styfle authored May 22, 2023
1 parent 815c256 commit 7230976
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions examples/with-mongodb/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import Head from 'next/head'
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 {
await clientPromise
// `await clientPromise` will use the default database passed in the MONGODB_URI
Expand Down

0 comments on commit 7230976

Please sign in to comment.