@@ -280,8 +280,7 @@ export abstract class AbstractCursor<
280
280
return done ( undefined , true ) ;
281
281
}
282
282
283
- next < any > ( this , true , ( err , doc ) => {
284
- // FIXME(NODE):
283
+ next < TSchema > ( this , true , ( err , doc ) => {
285
284
if ( err ) return done ( err ) ;
286
285
287
286
if ( doc ) {
@@ -296,9 +295,9 @@ export abstract class AbstractCursor<
296
295
}
297
296
298
297
/** Get the next available document from the cursor, returns null if no more documents are available. */
299
- next < T = TSchema > ( ) : Promise < T | null > ;
300
- next < T = TSchema > ( callback : Callback < T | null > ) : void ;
301
- next < T = TSchema > ( callback ?: Callback < T | null > ) : Promise < T | null > | void {
298
+ next ( ) : Promise < TSchema | null > ;
299
+ next ( callback : Callback < TSchema | null > ) : void ;
300
+ next ( callback ?: Callback < TSchema | null > ) : Promise < TSchema | null > | void {
302
301
return maybePromise ( callback , done => {
303
302
if ( this [ kId ] === Long . ZERO ) {
304
303
return done ( new MongoCursorExhaustedError ( ) ) ;
@@ -311,9 +310,9 @@ export abstract class AbstractCursor<
311
310
/**
312
311
* Try to get the next available document from the cursor or `null` if an empty batch is returned
313
312
*/
314
- tryNext < T = TSchema > ( ) : Promise < T | null > ;
315
- tryNext < T = TSchema > ( callback : Callback < T | null > ) : void ;
316
- tryNext < T = TSchema > ( callback ?: Callback < T | null > ) : Promise < T | null > | void {
313
+ tryNext ( ) : Promise < TSchema | null > ;
314
+ tryNext ( callback : Callback < TSchema | null > ) : void ;
315
+ tryNext ( callback ?: Callback < TSchema | null > ) : Promise < TSchema | null > | void {
317
316
return maybePromise ( callback , done => {
318
317
if ( this [ kId ] === Long . ZERO ) {
319
318
return done ( new MongoCursorExhaustedError ( ) ) ;
@@ -329,10 +328,10 @@ export abstract class AbstractCursor<
329
328
* @param iterator - The iteration callback.
330
329
* @param callback - The end callback.
331
330
*/
332
- forEach < T = TSchema > ( iterator : ( doc : T ) => boolean | void ) : Promise < void > ;
333
- forEach < T = TSchema > ( iterator : ( doc : T ) => boolean | void , callback : Callback < void > ) : void ;
334
- forEach < T = TSchema > (
335
- iterator : ( doc : T ) => boolean | void ,
331
+ forEach ( iterator : ( doc : TSchema ) => boolean | void ) : Promise < void > ;
332
+ forEach ( iterator : ( doc : TSchema ) => boolean | void , callback : Callback < void > ) : void ;
333
+ forEach (
334
+ iterator : ( doc : TSchema ) => boolean | void ,
336
335
callback ?: Callback < void >
337
336
) : Promise < void > | void {
338
337
if ( typeof iterator !== 'function' ) {
@@ -341,7 +340,7 @@ export abstract class AbstractCursor<
341
340
return maybePromise ( callback , done => {
342
341
const transform = this [ kTransform ] ;
343
342
const fetchDocs = ( ) => {
344
- next < T > ( this , true , ( err , doc ) => {
343
+ next < TSchema > ( this , true , ( err , doc ) => {
345
344
if ( err || doc == null ) return done ( err ) ;
346
345
let result ;
347
346
// NOTE: no need to transform because `next` will do this automatically
@@ -358,7 +357,7 @@ export abstract class AbstractCursor<
358
357
for ( let i = 0 ; i < internalDocs . length ; ++ i ) {
359
358
try {
360
359
result = iterator (
361
- ( transform ? transform ( internalDocs [ i ] ) : internalDocs [ i ] ) as T // TODO(NODE-3283): Improve transform typing
360
+ ( transform ? transform ( internalDocs [ i ] ) : internalDocs [ i ] ) as TSchema // TODO(NODE-3283): Improve transform typing
362
361
) ;
363
362
} catch ( error ) {
364
363
return done ( error ) ;
@@ -402,15 +401,15 @@ export abstract class AbstractCursor<
402
401
*
403
402
* @param callback - The result callback.
404
403
*/
405
- toArray < T = TSchema > ( ) : Promise < T [ ] > ;
406
- toArray < T = TSchema > ( callback : Callback < T [ ] > ) : void ;
407
- toArray < T = TSchema > ( callback ?: Callback < T [ ] > ) : Promise < T [ ] > | void {
404
+ toArray ( ) : Promise < TSchema [ ] > ;
405
+ toArray ( callback : Callback < TSchema [ ] > ) : void ;
406
+ toArray ( callback ?: Callback < TSchema [ ] > ) : Promise < TSchema [ ] > | void {
408
407
return maybePromise ( callback , done => {
409
- const docs : T [ ] = [ ] ;
408
+ const docs : TSchema [ ] = [ ] ;
410
409
const transform = this [ kTransform ] ;
411
410
const fetchDocs = ( ) => {
412
411
// NOTE: if we add a `nextBatch` then we should use it here
413
- next < T > ( this , true , ( err , doc ) => {
412
+ next < TSchema > ( this , true , ( err , doc ) => {
414
413
if ( err ) return done ( err ) ;
415
414
if ( doc == null ) return done ( undefined , docs ) ;
416
415
@@ -420,7 +419,7 @@ export abstract class AbstractCursor<
420
419
// these do need to be transformed since they are copying the rest of the batch
421
420
const internalDocs = ( transform
422
421
? this [ kDocuments ] . splice ( 0 , this [ kDocuments ] . length ) . map ( transform )
423
- : this [ kDocuments ] . splice ( 0 , this [ kDocuments ] . length ) ) as T [ ] ; // TODO(NODE-3283): Improve transform typing
422
+ : this [ kDocuments ] . splice ( 0 , this [ kDocuments ] . length ) ) as TSchema [ ] ; // TODO(NODE-3283): Improve transform typing
424
423
425
424
if ( internalDocs ) {
426
425
docs . push ( ...internalDocs ) ;
@@ -458,11 +457,12 @@ export abstract class AbstractCursor<
458
457
* Map all documents using the provided function
459
458
* If there is a transform set on the cursor, that will be called first and the result passed to
460
459
* this function's transform.
461
- * @remarks
462
460
*
463
- * **NOTE:** adding a transform changes the return type of the iteration of this cursor, it **does not** return
464
- * a new instance of a cursor. This means when calling map, you should always assign the result to a new
465
- * variable. Take note of the following example:
461
+ * @remarks
462
+ * **Note for Typescript Users:** adding a transform changes the return type of the iteration of this cursor,
463
+ * it **does not** return a new instance of a cursor. This means when calling map,
464
+ * you should always assign the result to a new variable in order to get a correctly typed cursor variable.
465
+ * Take note of the following example:
466
466
*
467
467
* @example
468
468
* ```typescript
0 commit comments