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

TypeScript insertMany return type isn't an array #10802

Closed
ahmedelshenawy25 opened this issue Sep 28, 2021 · 0 comments
Closed

TypeScript insertMany return type isn't an array #10802

ahmedelshenawy25 opened this issue Sep 28, 2021 · 0 comments
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@ahmedelshenawy25
Copy link
Contributor

ahmedelshenawy25 commented Sep 28, 2021

Do you want to request a feature or report a bug?
Bug
What is the current behavior?
insertMany return type isn't an array

Property 'map' does not exist on type 'Document<any, any, IBook> & IBook & { _id: ObjectId; }'

If the current behavior is a bug, please provide the steps to reproduce.

import mongoose from 'mongoose';

interface IBook {
  name: string;
}

async function run() {
  await mongoose.connect('mongodb://localhost:27017/test');

  const bookSchema = new mongoose.Schema<IBook>({
    name: String
  });

  const Book = mongoose.model<IBook>('Book', bookSchema);

  const books = await Book.insertMany({ name: 'aaaa' });
  console.log(Array.isArray(books)); // true
  books.map(book => console.log(book));
}

run().catch(console.error);
{
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}

What is the expected behavior?
insertMany return type should be an array
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node.js: v14.15.5
Mongoose: v6.0.8
MongoDB: v4.4.3

@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label Sep 28, 2021
@vkarpov15 vkarpov15 added this to the 6.0.10 milestone Oct 1, 2021
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
Development

No branches or pull requests

3 participants