From 2b4b2f965e57723eb28b58d629ebc9faa8ad7c10 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 8 Aug 2024 14:44:19 -0400 Subject: [PATCH] types(cursor): indicate that cursor.next() can return null Fix #14787 --- test/types/querycursor.test.ts | 2 ++ types/cursor.d.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/types/querycursor.test.ts b/test/types/querycursor.test.ts index f63f38370e1..81978059071 100644 --- a/test/types/querycursor.test.ts +++ b/test/types/querycursor.test.ts @@ -21,6 +21,8 @@ Test.find().cursor(). }). then(() => console.log('Done!')); +Test.find().cursor().next().then((doc) => expectType(doc)); + async function gh14374() { // `Parent` represents the object as it is stored in MongoDB interface Parent { diff --git a/types/cursor.d.ts b/types/cursor.d.ts index 5c467b866d5..888dd04c79b 100644 --- a/types/cursor.d.ts +++ b/types/cursor.d.ts @@ -51,7 +51,7 @@ declare module 'mongoose' { * Get the next document from this cursor. Will return `null` when there are * no documents left. */ - next(): Promise; + next(): Promise; options: Options; }