From 7230976317e3efed66265e115c036c92ec52b239 Mon Sep 17 00:00:00 2001 From: Ibrahem Mahyob Date: Tue, 23 May 2023 02:59:40 +0800 Subject: [PATCH] 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: Steven <229881+styfle@users.noreply.github.com> --- examples/with-mongodb/pages/index.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/with-mongodb/pages/index.tsx b/examples/with-mongodb/pages/index.tsx index 1a452c94fddf2..3a8420c103fbf 100644 --- a/examples/with-mongodb/pages/index.tsx +++ b/examples/with-mongodb/pages/index.tsx @@ -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