Skip to content

Commit a1d2bf9

Browse files
authored
Merge pull request #13965 from Automattic/vkarpov15/gh-13904
types(model): make InsertManyResult consistent with return type of insertMany
2 parents 96f71d5 + 83d1d75 commit a1d2bf9

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

test/types/models.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import mongoose, {
99
CallbackError,
1010
HydratedDocument,
1111
HydratedDocumentFromSchema,
12+
InsertManyResult,
1213
Query,
1314
UpdateWriteOpResult,
1415
AggregateOptions,
@@ -710,6 +711,23 @@ async function gh13746() {
710711
expectType<OkType>(findOneAndUpdateRes.ok);
711712
}
712713

714+
function gh13904() {
715+
const schema = new Schema({ name: String });
716+
717+
interface ITest {
718+
name?: string;
719+
}
720+
const Test = model<ITest>('Test', schema);
721+
722+
expectAssignable<Promise<InsertManyResult<ITest>>>(Test.insertMany(
723+
[{ name: 'test' }],
724+
{
725+
ordered: false,
726+
rawResult: true
727+
}
728+
));
729+
}
730+
713731
function gh13957() {
714732
class RepositoryBase<T> {
715733
protected model: mongoose.Model<T>;

types/models.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ declare module 'mongoose' {
374374
options: InsertManyOptions & { ordered: false; rawResult: true; }
375375
): Promise<mongodb.InsertManyResult<Require_id<TRawDocType>> & {
376376
mongoose: {
377-
validationErrors: Error[];
377+
validationErrors: (CastError | Error.ValidatorError)[];
378378
results: Array<
379379
Error |
380380
Object |
@@ -403,7 +403,7 @@ declare module 'mongoose' {
403403
options: InsertManyOptions & { ordered: false; rawResult: true; }
404404
): Promise<mongodb.InsertManyResult<Require_id<DocContents>> & {
405405
mongoose: {
406-
validationErrors: Error[];
406+
validationErrors: (CastError | Error.ValidatorError)[];
407407
results: Array<
408408
Error |
409409
Object |

0 commit comments

Comments
 (0)