Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insertMany return type changed from version 7.3.2 to 7.3.3 #13957

Closed
1 task done
ksyd9821 opened this issue Oct 9, 2023 · 2 comments · Fixed by #13964
Closed
1 task done

insertMany return type changed from version 7.3.2 to 7.3.3 #13957

ksyd9821 opened this issue Oct 9, 2023 · 2 comments · Fixed by #13964
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@ksyd9821
Copy link

ksyd9821 commented Oct 9, 2023

Prerequisites

  • I have written a descriptive issue title

Mongoose version

=7.3.3

Node.js version

18.x

MongoDB version

6.x

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

No response

Issue

It seems that the return type of the insertMany function changed with version 7.3.3.
The following code runs without any error on v7.3.2 and lower

import * as mongoose from "mongoose";

export class RepositoryBase<T> {
    protected model: mongoose.Model<T & mongoose.Document>;

    constructor(schemaModel: mongoose.Model<T & mongoose.Document>) {
        this.model = schemaModel;
    }

    async insertMany(elems: T[]): Promise<T[]> {
        elems = await this.model.insertMany(elems);
        return elems;
    }
}

while on versions >=7.3.3 the assignment inside the function generates this error:
image

The typescript version is 5.2.2.

@ksyd9821 ksyd9821 added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary help wanted labels Oct 9, 2023
@ksyd9821 ksyd9821 changed the title insertMany return type changed with from version 7.3.2 to 7.3.3 insertMany return type changed from version 7.3.2 to 7.3.3 Oct 9, 2023
@IslandRhythms IslandRhythms added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary help wanted labels Oct 10, 2023
vkarpov15 added a commit that referenced this issue Oct 10, 2023
…o generics to prevent errors when using `insertMany()` in generic classes

Fix #13957
@vkarpov15 vkarpov15 added typescript Types or Types-test related issue / Pull Request and removed confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. labels Oct 10, 2023
@vkarpov15 vkarpov15 added this to the 7.6.2 milestone Oct 10, 2023
vkarpov15 added a commit that referenced this issue Oct 11, 2023
types(models): add cleaner type definitions for `insertMany()` with no generics to prevent errors when using `insertMany()` in generic classes
@ksyd9821
Copy link
Author

Hi @vkarpov15 ,

I upgraded to version 7.6.2 which should fix this issue, but the error is still present with the code above.

@vkarpov15
Copy link
Collaborator

@ksyd9821 can you please open a new issue and follow the issue template? We added a test case in #13964 and that test case is passing, so you must have a different setup than OP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
3 participants