{"action":"created","issue":{"url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/issues/16315","repository_url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped","labels_url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/issues/16315/labels{/name}","comments_url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/issues/16315/comments","events_url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/issues/16315/events","html_url":"https://github.com/DefinitelyTyped/DefinitelyTyped/pull/16315","id":226252972,"number":16315,"title":"Add generic support to Collection and it's methods","user":{"login":"beary","id":6630583,"avatar_url":"https://avatars3.githubusercontent.com/u/6630583?v=3","gravatar_id":"","url":"https://api.github.com/users/beary","html_url":"https://github.com/beary","followers_url":"https://api.github.com/users/beary/followers","following_url":"https://api.github.com/users/beary/following{/other_user}","gists_url":"https://api.github.com/users/beary/gists{/gist_id}","starred_url":"https://api.github.com/users/beary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beary/subscriptions","organizations_url":"https://api.github.com/users/beary/orgs","repos_url":"https://api.github.com/users/beary/repos","events_url":"https://api.github.com/users/beary/events{/privacy}","received_events_url":"https://api.github.com/users/beary/received_events","type":"User","site_admin":false},"labels":[{"id":395679059,"url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/labels/Revision%20needed","name":"Revision needed","color":"b60205","default":false},{"id":617744507,"url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/labels/TypeScript%202.3","name":"TypeScript 2.3","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2017-05-04T11:35:50Z","updated_at":"2017-06-09T01:51:23Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/pulls/16315","html_url":"https://github.com/DefinitelyTyped/DefinitelyTyped/pull/16315","diff_url":"https://github.com/DefinitelyTyped/DefinitelyTyped/pull/16315.diff","patch_url":"https://github.com/DefinitelyTyped/DefinitelyTyped/pull/16315.patch"},"body":"Please fill in this template.\r\n\r\n- [X] Use a meaningful title for the pull request. Include the name of the package modified.\r\n- [X] Test the change in your own code. (Compile and run.)\r\n- [X] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request).\r\n- [X] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes).\r\n- [x] Run `npm run lint package-name` (or `tsc` if no `tslint.json` is present).\r\n\r\nSelect one of these and delete the others:\r\n\r\nIf changing an existing definition:\r\n- [X] Provide a URL to documentation or source code which provides context for the suggested changes: <<http://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-3.html>>\r\n- [ ] Increase the version number in the header if appropriate.\r\n- [ ] If you are making substantial changes, consider adding a `tslint.json` containing `{ \"extends\": \"dslint/dt.json\" }`.\r\n\r\nTypeScript support default generic since version 2.3, So I add generic to collection. When create a collection by `DB.collection()`or`DB.createCollection()`, developer could specify a scheme, and when do some query, the result can be static analysd.\r\n\r\nThese changes don't break the old cold.\r\n\r\neg:\r\n```typescript\r\nimport { MongoClient } from 'mongodb'\r\n\r\ninterface User {\r\n  name: string\r\n  gender: number\r\n}\r\n\r\ninterface SomeType {\r\n  // ...\r\n}\r\n\r\n\r\nMongoClient.connect('...').then(DB => {\r\n  // It's also support old code\r\n  DB\r\n    .collection('User')\r\n    .find()\r\n    .toArray()\r\n    .then(arr => {\r\n      arr.forEach(user => {\r\n        // user: any\r\n      })\r\n    })\r\n\r\n  DB\r\n    .collection<User>('User')\r\n    .find()\r\n    .toArray()\r\n    .then(arr => {\r\n      arr.forEach(user => {\r\n        console.log(user.gender) // user: User\r\n      })\r\n    })\r\n\r\n  DB\r\n    .collection<User>('User')\r\n    .aggregate<SomeType>([])\r\n    .toArray()\r\n    .then(arr => {\r\n      arr.forEach(item => {\r\n        // item: SomeType\r\n      })\r\n    })\r\n\r\n  DB\r\n    .collection<User>('User')\r\n    .findOne({})\r\n    .then(user => {\r\n      // user: User\r\n    })\r\n\r\n  DB\r\n    .collection<User>('User')\r\n    .findOne<SomeType>({}, { fields: {/* ... */ } }) // If pass fields option, could specify generic to `findOne()`\r\n    .then(user => {\r\n      // user: SomeType\r\n    })\r\n})\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/issues/comments/307273448","html_url":"https://github.com/DefinitelyTyped/DefinitelyTyped/pull/16315#issuecomment-307273448","issue_url":"https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/issues/16315","id":307273448,"user":{"login":"beary","id":6630583,"avatar_url":"https://avatars3.githubusercontent.com/u/6630583?v=3","gravatar_id":"","url":"https://api.github.com/users/beary","html_url":"https://github.com/beary","followers_url":"https://api.github.com/users/beary/followers","following_url":"https://api.github.com/users/beary/following{/other_user}","gists_url":"https://api.github.com/users/beary/gists{/gist_id}","starred_url":"https://api.github.com/users/beary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beary/subscriptions","organizations_url":"https://api.github.com/users/beary/orgs","repos_url":"https://api.github.com/users/beary/repos","events_url":"https://api.github.com/users/beary/events{/privacy}","received_events_url":"https://api.github.com/users/beary/received_events","type":"User","site_admin":false},"created_at":"2017-06-09T01:51:23Z","updated_at":"2017-06-09T01:51:23Z","body":"@CaselIT Thanks for remind, default type argument for `FindAndModifyWriteOpResultObject` was added. I realize sometimes people would use the interface as a type annotations, the default type argument is necessary."}}
{"actor":{"display_login":"beary"}}