Skip to content

Commit

Permalink
types(model): make InsertManyResult consistent with return type of in…
Browse files Browse the repository at this point in the history
…sertMany

Fix #13904
  • Loading branch information
vkarpov15 committed Oct 10, 2023
1 parent 642abd1 commit d2a4f73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions test/types/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import mongoose, {
CallbackError,
HydratedDocument,
HydratedDocumentFromSchema,
InsertManyResult,
Query,
UpdateWriteOpResult,
AggregateOptions,
Expand Down Expand Up @@ -709,3 +710,20 @@ async function gh13746() {
expectType<ObjectId | undefined>(findOneAndUpdateRes.lastErrorObject?.upserted);
expectType<OkType>(findOneAndUpdateRes.ok);
}

function gh13904() {
const schema = new Schema({ name: String });

interface ITest {
name?: string;
}
const Test = model<ITest>("Test", schema);

expectAssignable<Promise<InsertManyResult<ITest>>>(Test.insertMany(
[{ name: "test" }],
{
ordered: false,
rawResult: true
}
));
}
2 changes: 1 addition & 1 deletion types/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ declare module 'mongoose' {
options: InsertManyOptions & { ordered: false; rawResult: true; }
): Promise<mongodb.InsertManyResult<Require_id<DocContents>> & {
mongoose: {
validationErrors: Error[];
validationErrors: (CastError | Error.ValidatorError)[];
results: Array<
Error |
Object |
Expand Down

0 comments on commit d2a4f73

Please sign in to comment.