-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
[types] Model.create dosnt return array #9817
Comments
The problem seems to be here Line 634 in c44d521
/** Creates a new document or documents */
create<Z = T | DocumentDefinition<T>>(doc: Z): Promise<T>;
create<Z = T | DocumentDefinition<T>>(docs: Array<Z>, options?: SaveOptions): Promise<Array<T>>; If you don't specify an options parameter (although it's optional...) it will assume that the return value is Try to do this. It should help. await SomeModel.create([{ param1: "Hello", param2: 1 }], {}); I'm not sure how to fix that though - my guess would be that it should work, but it doesn't. I'm not as experienced with type declarations. |
thanks @Duchynko, do you know why this line is ignored then? Line 635 in c44d521
Note: i already manually tried to set the return of this line to |
@hasezoey I'm not sure, hah. I also tried to play around with this but didn't figure it out. Line 635 in c44d521
@vkarpov15 shouldn't the above overload return an array? I can create a PR if so... create<Z = T | DocumentDefinition<T>>(...docs: Array<Z>): Promise<Array<T>>; |
@Duchynko you're right, it should. Passing a spread of docs means you get a spread in the callback, but you do get an array of docs if you use a promise. Feel free to put in a PR 👍 |
actual issue should get fixed by #9890 (didnt test it yet) |
Do you want to request a feature or report a bug?
type-bug
What is the current behavior?
await SomeModel.create([doc1, doc2])
dosnt return an arrayIf the current behavior is a bug, please provide the steps to reproduce.
code used:
What is the expected behavior?
that
await SomeModel.create([doc1,doc2])
returns an arrayWhat are the versions of Node.js, Mongoose and MongoDB you are using?
mongoose 5.11.12
typescript 4.1.3
would have provided an pr, but didnt find an fix yet
The text was updated successfully, but these errors were encountered: