Skip to content

Commit

Permalink
types: make findOneAndDelete() without options return result doc, not…
Browse files Browse the repository at this point in the history
… ModifyResult

Fix #14130
  • Loading branch information
vkarpov15 committed Dec 4, 2023
1 parent 62b3f45 commit f0f7e75
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions test/types/models.test.ts
Expand Up @@ -853,3 +853,12 @@ async function gh14003() {
await TestModel.validate({ name: 'foo' }, ['name']);
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' })
);
}
6 changes: 3 additions & 3 deletions types/models.d.ts
Expand Up @@ -608,11 +608,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 f0f7e75

Please sign in to comment.