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<
385
385
/** @internal */
386
386
[ kResumeQueue ] : Denque < Callback < ChangeStreamCursor < TSchema , TChange > > > ;
387
387
/** @internal */
388
- [ kCursorStream ] ?: Readable ;
388
+ [ kCursorStream ] ?: Readable & AsyncIterable < TChange > ;
389
389
/** @internal */
390
390
[ kClosed ] : boolean ;
391
391
/** @internal */
@@ -473,7 +473,7 @@ export class ChangeStream<
473
473
}
474
474
475
475
/** @internal */
476
- get cursorStream ( ) : Readable | undefined {
476
+ get cursorStream ( ) : ( Readable & AsyncIterable < TChange > ) | undefined {
477
477
return this [ kCursorStream ] ;
478
478
}
479
479
@@ -542,7 +542,7 @@ export class ChangeStream<
542
542
* Return a modified Readable stream including a possible transform method.
543
543
* @throws MongoDriverError if this.cursor is undefined
544
544
*/
545
- stream ( options ?: CursorStreamOptions ) : Readable {
545
+ stream ( options ?: CursorStreamOptions ) : Readable & AsyncIterable < TChange > {
546
546
this . streamOptions = options ;
547
547
if ( ! this . cursor ) throw new MongoChangeStreamError ( NO_CURSOR_ERROR ) ;
548
548
return this . cursor . stream ( options ) ;
Original file line number Diff line number Diff line change @@ -258,7 +258,7 @@ export abstract class AbstractCursor<
258
258
} ;
259
259
}
260
260
261
- stream ( options ?: CursorStreamOptions ) : Readable {
261
+ stream ( options ?: CursorStreamOptions ) : Readable & AsyncIterable < TSchema > {
262
262
if ( options ?. transform ) {
263
263
const transform = options . transform ;
264
264
const readable = makeCursorStream ( this ) ;
Original file line number Diff line number Diff line change @@ -30,9 +30,15 @@ const cursor = collection
30
30
. sort ( { } )
31
31
. map ( result => ( { foo : result . age } ) ) ;
32
32
33
+ const cursorStream = cursor . stream ( ) ;
33
34
expectType < FindCursor < { foo : number } > > ( cursor ) ;
34
- expectType < Readable > ( cursor . stream ( ) ) ;
35
+ expectType < Readable & AsyncIterable < { foo : number } > > ( cursorStream ) ;
35
36
expectType < FindCursor < Document > > ( cursor . project ( { } ) ) ;
37
+ ( async ( ) => {
38
+ for await ( const doc of cursorStream ) {
39
+ expectType < { foo : number } > ( doc ) ;
40
+ }
41
+ } ) ( ) ;
36
42
37
43
collection . find ( ) . project ( { } ) ;
38
44
collection . find ( ) . project ( { notExistingField : 1 } ) ;
You can’t perform that action at this time.
0 commit comments