Skip to content

Commit

Permalink
Merge pull request #14152 from Automattic/vkarpov15/gh-13999
Browse files Browse the repository at this point in the history
types(model): add no-generic override for `insertMany()` with options
  • Loading branch information
vkarpov15 committed Dec 5, 2023
2 parents 62b3f45 + 8b9f717 commit cc46cfb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/types/models.test.ts
Expand Up @@ -853,3 +853,19 @@ async function gh14003() {
await TestModel.validate({ name: 'foo' }, ['name']);
await TestModel.validate({ name: 'foo' }, { pathsToSkip: ['name'] });
}

async function gh13999() {
class RepositoryBase<T> {
protected model: mongoose.Model<T>;

constructor(schemaModel: mongoose.Model<T>) {
this.model = schemaModel;
}

async insertMany(elems: T[]): Promise<T[]> {
elems = await this.model.insertMany(elems, { session: null });
return elems;
}
}

}
4 changes: 4 additions & 0 deletions types/models.d.ts
Expand Up @@ -395,6 +395,10 @@ declare module 'mongoose' {
docs: Array<TRawDocType>,
options: InsertManyOptions & { rawResult: true; }
): Promise<mongodb.InsertManyResult<Require_id<THydratedDocumentType>>>;
insertMany(
doc: Array<TRawDocType>,
options: InsertManyOptions
): Promise<Array<THydratedDocumentType>>;
insertMany<DocContents = TRawDocType>(
docs: Array<DocContents | TRawDocType>,
options: InsertManyOptions & { lean: true; }
Expand Down

0 comments on commit cc46cfb

Please sign in to comment.