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

ts: fix query async iterator definition #10251

Merged

Conversation

borfig
Copy link
Contributor

@borfig borfig commented May 15, 2021

Fixes #10250

  1. The async iterator is supposed to be a method and not a property;
  2. According to underlying implementation, it returns an asyncIterator
    and not a query cursor.

Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. The two fields below are mandatory.

If you're making a change to documentation, do not modify a .html file directly. Instead find the corresponding .pug file or test case in the test/docs directory.

Summary

This PR addresses #10250

Examples

The following code now compiles:

import { Schema, model } from "mongoose";
interface Test {
  test: string;
}
const schema = new Schema<Test>({
  test: { type: String, required: true },
});
const TestModel = model<Test>("Test", schema);
async function main() {
  const query = TestModel.find({});
  for await (const test of query) {
    console.log(test);
  }
}

Fixes Automattic#10250

1. The async iterator is supposed to be a method and not a property;
2. According to underlying implementation, it returns an asyncIterator
   and not a query cursor.
Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks! 👍

@vkarpov15 vkarpov15 added this to the 5.12.10 milestone May 16, 2021
@vkarpov15 vkarpov15 merged commit 6177c4c into Automattic:master May 16, 2021
@borfig borfig deleted the fix-query-async-iterator-type branch May 17, 2021 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

It is not possible to use for-await with queries in typescript
2 participants