-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
mongodb.d.ts fixes to enable Promise and async-await scenarios #9024
Conversation
Various fixes to enable Promise and async-await scenarios... - Db.command: fix incorrect function overload signature - Collection.aggregate: fix incorrect function overload signature - Collection.find: add missing overload signature - Collection.findOne: add missing interface function - Collection.initializeOrderedBulkOp: correct type of option parameter - Collection.initializeUnorderedBulkOp: correct type of option parameter - Collection.insert: add missing interface function - Collection.update: add missing interface function - OrderedBulkOperation.execute: fix incorrect function overload signature - UnorderedBulkOperation.execute: fix incorrect function overload signature Fix spelling errors: CollectionAggrigationOptions -> CollectionAggregationOptions
Update mongodb.d.ts
mongodb/mongodb.d.ts to author (@CaselIT). Could you review this PR? Checklist
|
The options in |
Totally understand the motive to omit legacy functions, but here's an argument to consider keeping them... Omitting a legacy declaration prevents users from targeting a down-level (pre-3.2) mongodb instance that doesn't yet support the new interface. If the driver still exposes the interface (which it does), then so should the typing. Arguably an ideal way to deal with this situation would be if the TypeScript compiler had a way to flag obsolete declarations. But since we don't have that feature yet, my suggestion would be to keep legacy declarations and perhaps comment them as //obsolete in the code. |
I guess you have a point here. |
@davetemplin I've updated the definition with the deprecated method you suggested for typings. If you use it you can install them with |
Thank you for making these updates. Great to see the legacy functions reintroduced but flagged as deprecated. However, a few other important details unfortunately got lost in the translation... SUMMARY:
DETAILS: 1. For Collection.aggregate the return-type of "void|AggregationCursor" prevents applying cursor functions (such as toArray) without explicit casts. For example we should be able to write a simple aggregate statement like the following... EXAMPLE: Suggest in this case not trying to represent the void return type at all. Perhaps anyone who passes a callback isn't going to care about the return type anyway. 2. The secondary Collection.find overload was not added and prevents projecting, skipping and limiting. EXAMPLE: 3. The Db.command function does not return a Promise if options is passed, which prevents accessing the result. EXAMPLE: 4. The options argument initializeOrderedBulkOp and initializeUnorderedBulkOp should be optional. EXAMPLE: SUGGESTED CHANGES: for Db ...
Please note the callback must not be optional in the first declaration, otherwise it becomes ambiguous with the second declaration (masking out the promise since it is defined first). Again, suggest not worrying about the void case as above. for Collection ...
for OrderedBulkOperation and UnorderedBulkOperation ...
I appreciate there are a lot of scenarios and subtleties here and it's really tough to validate them all. But these additional changes if made should make mongodb work really well with async-await! |
@davetemplin I've added the updates you suggested, could you check them here Think7/typings-mongodb@deed273 ? Thanks for them. Regarding the |
The changes on Think7 look good, thanks!! By the way I also just now noticed Regarding the |
Added the missing signatures Think7/typings-mongodb@1061602 |
Splendid, thanks! ...would like to see these changes have the broadest possible reach--so folks still using tsd or grabbing directly from GitHub directly will get these changes. |
You could update this pull request with a new push, else I can do a new pr with the new updates. |
New pull request submitted. One last thing we didn't catch before was on |
@davetemplin There is always something! 😄 I'll fix that. |
Various fixes to enable Promise and async-await scenarios...
Fix spelling errors: CollectionAggrigationOptions -> CollectionAggregationOptions