Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add type def for Aggreaget#model without arguments #12864

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion 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' } });
Expand All @@ -8,6 +8,7 @@ interface ITest extends Document {
}

const Test = model<ITest>('Test', schema);
const AnotherTest = model<ITest>('AnotherTest', schema);

Test.aggregate([{ $match: { name: 'foo' } }]).exec().then((res: any) => console.log(res));

Expand Down Expand Up @@ -60,6 +61,10 @@ async function run() {
expectType<ITest[]>(await Test.aggregate<ITest>().sort({ name: 'desc' }));
expectType<ITest[]>(await Test.aggregate<ITest>().sort({ name: 'descending' }));
expectType<ITest[]>(await Test.aggregate<ITest>().sort({ name: { $meta: 'textScore' } }));

// Aggregate.prototype.model()
expectType<Model<any>>(Test.aggregate<ITest>().model());
expectType<Aggregate<ITest[]>>(Test.aggregate<ITest>().model(AnotherTest));
}

function gh12017_1() {
Expand Down
5 changes: 5 additions & 0 deletions types/aggregate.d.ts
Expand Up @@ -166,6 +166,11 @@ declare module 'mongoose' {
*/
model(model: Model<any>): this;

/**
* Returns the current model bound to this aggregate object
*/
model(): Model<any>;

/**
* Append a new $near operator to this aggregation pipeline
* @param arg $near operator contents
Expand Down