@@ -280,8 +280,7 @@ export abstract class AbstractCursor<
280280 return done ( undefined , true ) ;
281281 }
282282
283- next < any > ( this , true , ( err , doc ) => {
284- // FIXME(NODE):
283+ next < TSchema > ( this , true , ( err , doc ) => {
285284 if ( err ) return done ( err ) ;
286285
287286 if ( doc ) {
@@ -296,9 +295,9 @@ export abstract class AbstractCursor<
296295 }
297296
298297 /** 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 {
302301 return maybePromise ( callback , done => {
303302 if ( this [ kId ] === Long . ZERO ) {
304303 return done ( new MongoCursorExhaustedError ( ) ) ;
@@ -311,9 +310,9 @@ export abstract class AbstractCursor<
311310 /**
312311 * Try to get the next available document from the cursor or `null` if an empty batch is returned
313312 */
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 {
317316 return maybePromise ( callback , done => {
318317 if ( this [ kId ] === Long . ZERO ) {
319318 return done ( new MongoCursorExhaustedError ( ) ) ;
@@ -329,10 +328,10 @@ export abstract class AbstractCursor<
329328 * @param iterator - The iteration callback.
330329 * @param callback - The end callback.
331330 */
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 ,
336335 callback ?: Callback < void >
337336 ) : Promise < void > | void {
338337 if ( typeof iterator !== 'function' ) {
@@ -341,7 +340,7 @@ export abstract class AbstractCursor<
341340 return maybePromise ( callback , done => {
342341 const transform = this [ kTransform ] ;
343342 const fetchDocs = ( ) => {
344- next < T > ( this , true , ( err , doc ) => {
343+ next < TSchema > ( this , true , ( err , doc ) => {
345344 if ( err || doc == null ) return done ( err ) ;
346345 let result ;
347346 // NOTE: no need to transform because `next` will do this automatically
@@ -358,7 +357,7 @@ export abstract class AbstractCursor<
358357 for ( let i = 0 ; i < internalDocs . length ; ++ i ) {
359358 try {
360359 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
362361 ) ;
363362 } catch ( error ) {
364363 return done ( error ) ;
@@ -402,15 +401,15 @@ export abstract class AbstractCursor<
402401 *
403402 * @param callback - The result callback.
404403 */
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 {
408407 return maybePromise ( callback , done => {
409- const docs : T [ ] = [ ] ;
408+ const docs : TSchema [ ] = [ ] ;
410409 const transform = this [ kTransform ] ;
411410 const fetchDocs = ( ) => {
412411 // 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 ) => {
414413 if ( err ) return done ( err ) ;
415414 if ( doc == null ) return done ( undefined , docs ) ;
416415
@@ -420,7 +419,7 @@ export abstract class AbstractCursor<
420419 // these do need to be transformed since they are copying the rest of the batch
421420 const internalDocs = ( transform
422421 ? 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
424423
425424 if ( internalDocs ) {
426425 docs . push ( ...internalDocs ) ;
@@ -458,11 +457,12 @@ export abstract class AbstractCursor<
458457 * Map all documents using the provided function
459458 * If there is a transform set on the cursor, that will be called first and the result passed to
460459 * this function's transform.
461- * @remarks
462460 *
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:
466466 *
467467 * @example
468468 * ```typescript
0 commit comments