Skip to content

Commit

Permalink
Added support for ts2.3 default generic types
Browse files Browse the repository at this point in the history
  • Loading branch information
CaselIT committed Apr 28, 2017
1 parent 886cdd2 commit c234995
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
15 changes: 9 additions & 6 deletions types/mongodb/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Project: https://github.com/mongodb/node-mongodb-native/tree/2.2
// Definitions by: Federico Caselli <https://github.com/CaselIT>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Typescript Version: 2.3

// Documentation : http://mongodb.github.io/node-mongodb-native/2.2/api/

Expand Down Expand Up @@ -962,8 +963,10 @@ export interface WriteOpResult {
//http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#~resultCallback
export type CursorResult = any | void | boolean;

type Default = { [key: string]: any };

//http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html
export class Cursor<T> extends Readable {
export class Cursor<T = Default> extends Readable {

sortValue: string;
timeout: boolean;
Expand Down Expand Up @@ -1014,8 +1017,8 @@ export class Cursor<T> extends Readable {
// http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#min
min(min: number): Cursor<T>;
// http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#next
next(): Promise<CursorResult>;
next(callback: MongoCallback<CursorResult>): void;
next(): Promise<T>;
next(callback: MongoCallback<T>): void;
//http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#project
project(value: Object): Cursor<T>;
//http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#read
Expand Down Expand Up @@ -1067,7 +1070,7 @@ export interface EndCallback {
//http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#~resultCallback
export type AggregationCursorResult = any | void;
//http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html
export class AggregationCursor<T> extends Readable {
export class AggregationCursor<T = Default> extends Readable {
// http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#batchSize
batchSize(value: number): AggregationCursor<T>;
// http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#clone
Expand All @@ -1093,8 +1096,8 @@ export class AggregationCursor<T> extends Readable {
// http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#maxTimeMS
maxTimeMS(value: number): AggregationCursor<T>;
// http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#next
next(): Promise<AggregationCursorResult>;
next(callback: MongoCallback<AggregationCursorResult>): void;
next(): Promise<T>;
next(callback: MongoCallback<T>): void;
// http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#out
out(destination: string): AggregationCursor<T>;
//http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#project
Expand Down
6 changes: 3 additions & 3 deletions types/mongodb/mongodb-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err: mongodb.Mong
});

{
let cursor: mongodb.Cursor<any>;
let cursor: mongodb.Cursor;
cursor = collection.find();
cursor = cursor.addCursorFlag('',true);
cursor = cursor.addQueryModifier('',true);
Expand Down Expand Up @@ -57,14 +57,14 @@ MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err: mongodb.Mong
// Collection .findM<T>() & .agggregate<T>() generic tests
{
let bag : {cost: number, color: string};
type bag = typeof bag;
type bag = typeof bag;
let cursor: mongodb.Cursor<bag> = collection.find<bag>({color: 'black'})
cursor.toArray(function (err,r) { r[0].cost} );
cursor.forEach(function (bag ) { bag.color }, () => {});
}
{
let payment: {total: number};
type payment = typeof payment;
type payment = typeof payment;
let cursor: mongodb.AggregationCursor<payment> = collection.aggregate<payment>([{}])
}
})

0 comments on commit c234995

Please sign in to comment.