Skip to content

Commit d2a4f73

Browse files
committed
types(model): make InsertManyResult consistent with return type of insertMany
Fix #13904
1 parent 642abd1 commit d2a4f73

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
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,
@@ -709,3 +710,20 @@ async function gh13746() {
709710
expectType<ObjectId | undefined>(findOneAndUpdateRes.lastErrorObject?.upserted);
710711
expectType<OkType>(findOneAndUpdateRes.ok);
711712
}
713+
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+
}

types/models.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ declare module 'mongoose' {
375375
options: InsertManyOptions & { ordered: false; rawResult: true; }
376376
): Promise<mongodb.InsertManyResult<Require_id<DocContents>> & {
377377
mongoose: {
378-
validationErrors: Error[];
378+
validationErrors: (CastError | Error.ValidatorError)[];
379379
results: Array<
380380
Error |
381381
Object |

0 commit comments

Comments
 (0)