diff --git a/test/types/aggregate.test.ts b/test/types/aggregate.test.ts index 6284cd649fd..8d0d0bd16b3 100644 --- a/test/types/aggregate.test.ts +++ b/test/types/aggregate.test.ts @@ -1,4 +1,4 @@ -import { Schema, model, Document, Expression, PipelineStage, Types } from 'mongoose'; +import { Schema, model, Document, Expression, PipelineStage, Types, Model, Aggregate } from 'mongoose'; import { expectType } from 'tsd'; const schema: Schema = new Schema({ name: { type: 'String' } }); @@ -8,6 +8,7 @@ interface ITest extends Document { } const Test = model('Test', schema); +const AnotherTest = model('AnotherTest', schema); Test.aggregate([{ $match: { name: 'foo' } }]).exec().then((res: any) => console.log(res)); @@ -60,6 +61,10 @@ async function run() { expectType(await Test.aggregate().sort({ name: 'desc' })); expectType(await Test.aggregate().sort({ name: 'descending' })); expectType(await Test.aggregate().sort({ name: { $meta: 'textScore' } })); + + // Aggregate.prototype.model() + expectType>(Test.aggregate().model()); + expectType>(Test.aggregate().model(AnotherTest)); } function gh12017_1() { diff --git a/types/aggregate.d.ts b/types/aggregate.d.ts index 7264a2f7db1..926e878fcdd 100644 --- a/types/aggregate.d.ts +++ b/types/aggregate.d.ts @@ -166,6 +166,11 @@ declare module 'mongoose' { */ model(model: Model): this; + /** + * Returns the current model bound to this aggregate object + */ + model(): Model; + /** * Append a new $near operator to this aggregation pipeline * @param arg $near operator contents