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 all commits
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
4 changes: 4 additions & 0 deletions test/types/connection.test.ts
Expand Up @@ -20,6 +20,10 @@ conn.readyState === 99;

expectError(conn.readyState = 0);

expectType<Promise<Record<string, Error | mongodb.Collection<any>>>>(
conn.createCollections()
);

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(continueOnError?: boolean): Promise<Record<string, Error | mongodb.Collection<any>>>;

/**
* 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