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

add type for createCollections #14295

Merged
merged 3 commits into from Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/types/connection.test.ts
Expand Up @@ -20,6 +20,8 @@ conn.readyState === 99;

expectError(conn.readyState = 0);

expectError(conn.createCollections());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this expectError here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You said to write a test showing it could be used in typescript.

Copy link
Collaborator

Choose a reason for hiding this comment

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

expectError() means you expect the code within to cause a TypeScript compiler error. The problem isn't the test, just the expectError().


expectType<Connection>(new Connection());
expectType<Promise<Connection>>(new Connection().asPromise());

Expand Down
5 changes: 5 additions & 0 deletions types/connection.d.ts
Expand Up @@ -81,6 +81,11 @@ declare module 'mongoose' {
*/
createCollection<T extends AnyObject = AnyObject>(name: string, options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<T>>;

/**
* https://mongoosejs.com/docs/api/connection.html#Connection.prototype.createCollections()
*/
createCollections<T extends AnyObject = AnyObject>(continueOnError?: boolean): Promise<mongodb.Collection<T>>;

/**
* Removes the model named `name` from this connection, if it exists. You can
* use this function to clean up any models you created in your tests to
Expand Down