Skip to content

Commit

Permalink
types(model): correct return type for findByIdAndDelete()
Browse files Browse the repository at this point in the history
Fix #14190
  • Loading branch information
vkarpov15 committed Dec 26, 2023
1 parent 3bd67a8 commit 7d1f4e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions test/types/queries.test.ts
Expand Up @@ -520,3 +520,11 @@ function gh13630() {
const x: UpdateQueryKnownOnly<User> = { $set: { name: 'John' } };
expectAssignable<UpdateQuery<User>>(x);
}

function gh14190() {
const userSchema = new Schema({ name: String, age: Number });
const UserModel = model('User', userSchema);

const doc = await UserModel.findByIdAndDelete('0'.repeat(24));
expectType<ReturnType<(typeof UserModel)['hydrate']> | null>(doc);
}
4 changes: 2 additions & 2 deletions types/models.d.ts
Expand Up @@ -564,8 +564,8 @@ declare module 'mongoose' {
'findOneAndDelete'
>;
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
id?: mongodb.ObjectId | any,
options?: QueryOptions<TRawDocType> & { includeResultMetadata: true }
id: mongodb.ObjectId | any,
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;
findByIdAndDelete<ResultDoc = THydratedDocumentType>(
id?: mongodb.ObjectId | any,
Expand Down

0 comments on commit 7d1f4e4

Please sign in to comment.