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] Collection.find() & .aggregate() cursor generics #14012
[mongodb] Collection.find() & .aggregate() cursor generics #14012
Conversation
mongodb/index.d.ts to author (@CaselIT). Could you review this PR? Checklist
|
This will break backward compatibility. If you want to use a typed version manually install it from the typings repo
|
You need to explain it more precisely and what the interface it will break exactly before considering pr to close. |
If you used any of the classes that are now generic as a type annotation you will now have an error of the type Example if you had: let c: Cursor; Typescript will not output |
Just use any type let c: Cursor<any>; Now NO backward compatibility is broken. |
@hinell that is exactly the problem. If you have an existing project that uses the current definition that would break and you would need to go and modify all the types that are now generics. |
@CaselIT |
I'll let the maintainers decide. |
@CaselIT Well guys what about if I'll extract generics into a separate interface? |
@hinell Looks like there are some merge conflicts. Please refresh the PR so we can merge. |
Also have removed an extra `extends any` declaration
@bowdenk7 Here we go... |
Merge remote-tracking branch 'upstream/master' into mongodb.collection.generics
mongodb/index.d.ts
Outdated
@@ -1222,13 +1226,13 @@ export interface EndCallback { | |||
|
|||
//http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#~resultCallback | |||
export type AggregationCursorResult = any | void; | |||
|
|||
// TODO: change to generic version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove TODO.
mongodb/index.d.ts
Outdated
// http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#clone | ||
clone(): Cursor; | ||
// https://github.com/christkv/mongodb-core/blob/2.0/lib/cursor.js#L333 | ||
clone(): Cursor<T>; // still returns the same type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove comment.
Description
Featuring generics on the
Cursor
,AggregateCursor
,Collection.find()
andCollection.aggregate()
methods respectively.Now we can do things like this:
Q: Why not to just declare the generic right on the
db.collection()
method andCollection
interface as proposed by #13731?Cause there are only a few methods that use the type that generic variable provides and also this would be sort of extra job creating mess and confusing users. So if you feel that you need another one extra generic-typed method like these one then just let me know.
Template
master
branch.tsc
without errors.npm run lint package-name
if atslint.json
is present.