Skip to content

Commit 7d1f4e4

Browse files
committed
types(model): correct return type for findByIdAndDelete()
Fix #14190
1 parent 3bd67a8 commit 7d1f4e4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

test/types/queries.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,11 @@ function gh13630() {
520520
const x: UpdateQueryKnownOnly<User> = { $set: { name: 'John' } };
521521
expectAssignable<UpdateQuery<User>>(x);
522522
}
523+
524+
function gh14190() {
525+
const userSchema = new Schema({ name: String, age: Number });
526+
const UserModel = model('User', userSchema);
527+
528+
const doc = await UserModel.findByIdAndDelete('0'.repeat(24));
529+
expectType<ReturnType<(typeof UserModel)['hydrate']> | null>(doc);
530+
}

types/models.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,8 @@ declare module 'mongoose' {
564564
'findOneAndDelete'
565565
>;
566566
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
567-
id?: mongodb.ObjectId | any,
568-
options?: QueryOptions<TRawDocType> & { includeResultMetadata: true }
567+
id: mongodb.ObjectId | any,
568+
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
569569
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;
570570
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
571571
id?: mongodb.ObjectId | any,

0 commit comments

Comments
 (0)