Automattic / mongoose

MongoDB object modeling designed to work in an asynchronous environment.
https://mongoosejs.com
MIT License
26.96k stars 3.84k forks source link

insertMany return type changed from version 7.3.2 to 7.3.3 #13957

Closed ksyd9821 closed 1 year ago

ksyd9821 commented 1 year ago

Prerequisites

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 commented 1 year ago

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 commented 1 year ago

@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.