Skip to content

Commit

Permalink
Merge pull request #14153 from Automattic/vkarpov15/gh-14130
Browse files Browse the repository at this point in the history
types: make findOneAndDelete() without options return result doc, not ModifyResult
  • Loading branch information
vkarpov15 committed Dec 5, 2023
2 parents cc46cfb + ffdb091 commit 4d7f71d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 9 additions & 1 deletion test/types/models.test.ts
Expand Up @@ -854,6 +854,15 @@ async function gh14003() {
await TestModel.validate({ name: 'foo' }, { pathsToSkip: ['name'] });
}

async function gh14114() {
const schema = new mongoose.Schema({ name: String });
const Test = mongoose.model('Test', schema);

expectType<ReturnType<(typeof Test)['hydrate']> | null>(
await Test.findOneAndDelete({ name: 'foo' })
);
}

async function gh13999() {
class RepositoryBase<T> {
protected model: mongoose.Model<T>;
Expand All @@ -867,5 +876,4 @@ async function gh13999() {
return elems;
}
}

}
6 changes: 3 additions & 3 deletions types/models.d.ts
Expand Up @@ -612,11 +612,11 @@ declare module 'mongoose' {
'findOneAndDelete'
>;
findOneAndDelete<ResultDoc = THydratedDocumentType>(
filter?: FilterQuery<TRawDocType>,
options?: QueryOptions<TRawDocType> & { includeResultMetadata: true }
filter: FilterQuery<TRawDocType>,
options: QueryOptions<TRawDocType> & { includeResultMetadata: true }
): QueryWithHelpers<ModifyResult<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;
findOneAndDelete<ResultDoc = THydratedDocumentType>(
filter?: FilterQuery<TRawDocType>,
filter?: FilterQuery<TRawDocType> | null,
options?: QueryOptions<TRawDocType> | null
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>;

Expand Down

0 comments on commit 4d7f71d

Please sign in to comment.