Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ import {
} from './utils';
import { WriteConcern, WriteConcernOptions } from './write_concern';

/** @public */
/**
* @public
* @deprecated Will return the actual result document in 5.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to clarify here that this type will be removed and the findOneAnd... methods will return the result document directly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment now more detailed about the deprecation.

*/
export interface ModifyResult<TSchema = Document> {
value: WithId<TSchema> | null;
lastErrorObject?: Document;
Expand Down
18 changes: 18 additions & 0 deletions test/types/community/collection/findX.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,21 @@ expectType<WithId<{ a: number; b: string }> | null>(
expectType<WithId<{ a: number; b: string }> | null>(
(await coll.findOneAndDelete({ a: 3 }, { projection: { _id: 0 } })).value
);

// NODE-3568: Uncomment when ModifyResult is removed in 5.0
// expectType<Document> | null>((await coll.findOneAndDelete({ a: 3 })));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these expectations, the actual outcome will be WithId<TSchema> | null where TSchema is { a: number; b: string } because of line 329

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

// expectType<Document | null>(
// (await coll.findOneAndReplace({ a: 3 }, { a: 5, b: 'new string' }))
// );
// expectType<Document | null>(
// (
// await coll.findOneAndUpdate(
// { a: 3 },
// {
// $set: {
// a: 5
// }
// }
// )
// )
// );