Skip to content

Commit

Permalink
Merge pull request #13965 from Automattic/vkarpov15/gh-13904
Browse files Browse the repository at this point in the history
types(model): make InsertManyResult consistent with return type of insertMany
  • Loading branch information
vkarpov15 committed Oct 11, 2023
2 parents 96f71d5 + 83d1d75 commit a1d2bf9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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 @@ -710,6 +711,23 @@ async function gh13746() {
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
}
));
}

function gh13957() {
class RepositoryBase<T> {
protected model: mongoose.Model<T>;
Expand Down
4 changes: 2 additions & 2 deletions types/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ declare module 'mongoose' {
options: InsertManyOptions & { ordered: false; rawResult: true; }
): Promise<mongodb.InsertManyResult<Require_id<TRawDocType>> & {
mongoose: {
validationErrors: Error[];
validationErrors: (CastError | Error.ValidatorError)[];
results: Array<
Error |
Object |
Expand Down Expand Up @@ -403,7 +403,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 a1d2bf9

Please sign in to comment.