Skip to content

Commit cc46cfb

Browse files
authored
Merge pull request #14152 from Automattic/vkarpov15/gh-13999
types(model): add no-generic override for `insertMany()` with options
2 parents 62b3f45 + 8b9f717 commit cc46cfb

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

test/types/models.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,3 +853,19 @@ async function gh14003() {
853853
await TestModel.validate({ name: 'foo' }, ['name']);
854854
await TestModel.validate({ name: 'foo' }, { pathsToSkip: ['name'] });
855855
}
856+
857+
async function gh13999() {
858+
class RepositoryBase<T> {
859+
protected model: mongoose.Model<T>;
860+
861+
constructor(schemaModel: mongoose.Model<T>) {
862+
this.model = schemaModel;
863+
}
864+
865+
async insertMany(elems: T[]): Promise<T[]> {
866+
elems = await this.model.insertMany(elems, { session: null });
867+
return elems;
868+
}
869+
}
870+
871+
}

types/models.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ declare module 'mongoose' {
395395
docs: Array<TRawDocType>,
396396
options: InsertManyOptions & { rawResult: true; }
397397
): Promise<mongodb.InsertManyResult<Require_id<THydratedDocumentType>>>;
398+
insertMany(
399+
doc: Array<TRawDocType>,
400+
options: InsertManyOptions
401+
): Promise<Array<THydratedDocumentType>>;
398402
insertMany<DocContents = TRawDocType>(
399403
docs: Array<DocContents | TRawDocType>,
400404
options: InsertManyOptions & { lean: true; }

0 commit comments

Comments
 (0)