Skip to content

Commit

Permalink
fix: enumerate function override call signatures (#2687)
Browse files Browse the repository at this point in the history
Function overrides now declare each possible form
of the call signature, including the actual call signature

NODE-2934
  • Loading branch information
nbbeeken authored Jan 11, 2021
1 parent cc4b9e0 commit 2492dd2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/cmap/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ export class Connection extends EventEmitter {
}

destroy(): void;
destroy(callback?: Callback): void;
destroy(options?: DestroyOptions): void;
destroy(options?: DestroyOptions, callback?: Callback): void;
destroy(callback: Callback): void;
destroy(options: DestroyOptions): void;
destroy(options: DestroyOptions, callback: Callback): void;
destroy(options?: DestroyOptions | Callback, callback?: Callback): void {
if (typeof options === 'function') {
callback = options;
Expand Down
2 changes: 0 additions & 2 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,6 @@ export class Collection {
* @param pipeline - An array of {@link https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
* @param options - Optional settings for the command
*/
watch(): ChangeStream;
watch(pipeline?: Document[]): ChangeStream;
watch(pipeline?: Document[], options?: ChangeStreamOptions): ChangeStream {
pipeline = pipeline || [];
options = options ?? {};
Expand Down
2 changes: 1 addition & 1 deletion src/cursor/aggregation_cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class AggregationCursor extends AbstractCursor {
/** Execute the explain for the cursor */
explain(): Promise<Document>;
explain(callback: Callback): void;
explain(verbosity?: ExplainVerbosityLike): Promise<Document>;
explain(verbosity: ExplainVerbosityLike): Promise<Document>;
explain(
verbosity?: ExplainVerbosityLike | Callback,
callback?: Callback<Document>
Expand Down
8 changes: 6 additions & 2 deletions src/mongo_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export class MongoClient extends EventEmitter {
* @see docs.mongodb.org/manual/reference/connection-string/
*/
connect(): Promise<MongoClient>;
connect(callback?: Callback<MongoClient>): void;
connect(callback: Callback<MongoClient>): void;
connect(callback?: Callback<MongoClient>): Promise<MongoClient> | void {
if (callback && typeof callback !== 'function') {
throw new TypeError('`connect` only accepts a callback');
Expand Down Expand Up @@ -457,7 +457,11 @@ export class MongoClient extends EventEmitter {
// Create client
const mongoClient = new MongoClient(url, options);
// Execute the connect method
return mongoClient.connect(callback);
if (callback) {
return mongoClient.connect(callback);
} else {
return mongoClient.connect();
}
} catch (error) {
if (callback) return callback(error);
else return PromiseProvider.get().reject(error);
Expand Down

0 comments on commit 2492dd2

Please sign in to comment.