File tree Expand file tree Collapse file tree 3 files changed +11
-5
lines changed
Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -385,7 +385,7 @@ export class ChangeStream<
385385 /** @internal */
386386 [ kResumeQueue ] : Denque < Callback < ChangeStreamCursor < TSchema , TChange > > > ;
387387 /** @internal */
388- [ kCursorStream ] ?: Readable ;
388+ [ kCursorStream ] ?: Readable & AsyncIterable < TChange > ;
389389 /** @internal */
390390 [ kClosed ] : boolean ;
391391 /** @internal */
@@ -473,7 +473,7 @@ export class ChangeStream<
473473 }
474474
475475 /** @internal */
476- get cursorStream ( ) : Readable | undefined {
476+ get cursorStream ( ) : ( Readable & AsyncIterable < TChange > ) | undefined {
477477 return this [ kCursorStream ] ;
478478 }
479479
@@ -542,7 +542,7 @@ export class ChangeStream<
542542 * Return a modified Readable stream including a possible transform method.
543543 * @throws MongoDriverError if this.cursor is undefined
544544 */
545- stream ( options ?: CursorStreamOptions ) : Readable {
545+ stream ( options ?: CursorStreamOptions ) : Readable & AsyncIterable < TChange > {
546546 this . streamOptions = options ;
547547 if ( ! this . cursor ) throw new MongoChangeStreamError ( NO_CURSOR_ERROR ) ;
548548 return this . cursor . stream ( options ) ;
Original file line number Diff line number Diff line change @@ -258,7 +258,7 @@ export abstract class AbstractCursor<
258258 } ;
259259 }
260260
261- stream ( options ?: CursorStreamOptions ) : Readable {
261+ stream ( options ?: CursorStreamOptions ) : Readable & AsyncIterable < TSchema > {
262262 if ( options ?. transform ) {
263263 const transform = options . transform ;
264264 const readable = makeCursorStream ( this ) ;
Original file line number Diff line number Diff line change @@ -30,9 +30,15 @@ const cursor = collection
3030 . sort ( { } )
3131 . map ( result => ( { foo : result . age } ) ) ;
3232
33+ const cursorStream = cursor . stream ( ) ;
3334expectType < FindCursor < { foo : number } > > ( cursor ) ;
34- expectType < Readable > ( cursor . stream ( ) ) ;
35+ expectType < Readable & AsyncIterable < { foo : number } > > ( cursorStream ) ;
3536expectType < FindCursor < Document > > ( cursor . project ( { } ) ) ;
37+ ( async ( ) => {
38+ for await ( const doc of cursorStream ) {
39+ expectType < { foo : number } > ( doc ) ;
40+ }
41+ } ) ( ) ;
3642
3743collection . find ( ) . project ( { } ) ;
3844collection . find ( ) . project ( { notExistingField : 1 } ) ;
You can’t perform that action at this time.
0 commit comments