Skip to content

Commit

Permalink
Merge pull request Automattic#13208 from lpizzinidev/Automatticgh-13206
Browse files Browse the repository at this point in the history
types(model): aligned `watch()` type for mongodb 4.6.0
  • Loading branch information
vkarpov15 committed Apr 5, 2023
2 parents 1ae3088 + 3ac9964 commit 90ea063
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion test/types/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from 'mongoose';
import { expectAssignable, expectError, expectType } from 'tsd';
import { AutoTypedSchemaType, autoTypedSchema } from './schema.test';
import { UpdateOneModel } from 'mongodb';
import { UpdateOneModel, ChangeStreamInsertDocument } from 'mongodb';

function rawDocSyntax(): void {
interface ITest {
Expand Down Expand Up @@ -567,3 +567,14 @@ async function gh13151() {
if (!test) return;
expectType<ITest & { _id: Types.ObjectId }>(test);
}

function gh13206() {
interface ITest {
name: string;
}
const TestSchema = new Schema({ name: String });
const TestModel = model<ITest>('Test', TestSchema);
TestModel.watch<ITest, ChangeStreamInsertDocument<ITest>>([], { fullDocument: 'updateLookup' }).on('change', (change) => {
expectType<ChangeStreamInsertDocument<ITest>>(change);
});
}
2 changes: 1 addition & 1 deletion types/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ declare module 'mongoose' {
validate(optional: any, pathsToValidate: PathsToValidate): Promise<void>;

/** Watches the underlying collection for changes using [MongoDB change streams](https://www.mongodb.com/docs/manual/changeStreams/). */
watch<ResultType extends mongodb.Document = any>(pipeline?: Array<Record<string, unknown>>, options?: mongodb.ChangeStreamOptions & { hydrate?: boolean }): mongodb.ChangeStream<ResultType>;
watch<ResultType extends mongodb.Document = any, ChangeType extends mongodb.ChangeStreamDocument = any>(pipeline?: Array<Record<string, unknown>>, options?: mongodb.ChangeStreamOptions & { hydrate?: boolean }): mongodb.ChangeStream<ResultType, ChangeType>;

/** Adds a `$where` clause to this query */
$where(argument: string | Function): QueryWithHelpers<Array<THydratedDocumentType>, THydratedDocumentType, TQueryHelpers, TRawDocType>;
Expand Down

0 comments on commit 90ea063

Please sign in to comment.