@@ -3,6 +3,7 @@ import { MongoClient } from '../../src/mongo_client';
3
3
import { Collection } from '../../src/collection' ;
4
4
import { AggregationCursor } from '../../src/cursor/aggregation_cursor' ;
5
5
import type { FindCursor } from '../../src/cursor/find_cursor' ;
6
+ import type { ChangeStreamDocument } from '../../src/change_stream' ;
6
7
import type { Document } from 'bson' ;
7
8
import { Db } from '../../src' ;
8
9
import { Topology } from '../../src/sdam/topology' ;
@@ -19,9 +20,14 @@ expectDeprecated(Db.prototype.unref);
19
20
expectDeprecated ( MongoDBDriver . ObjectID ) ;
20
21
expectNotDeprecated ( MongoDBDriver . ObjectId ) ;
21
22
23
+ interface TSchema extends Document {
24
+ name : string ;
25
+ }
26
+
22
27
// test mapped cursor types
23
28
const client = new MongoClient ( '' ) ;
24
- const coll = client . db ( 'test' ) . collection ( 'test' ) ;
29
+ const db = client . db ( 'test' ) ;
30
+ const coll = db . collection ( 'test' ) ;
25
31
const findCursor = coll . find ( ) ;
26
32
expectType < Document | null > ( await findCursor . next ( ) ) ;
27
33
const mappedFind = findCursor . map < number > ( obj => Object . keys ( obj ) . length ) ;
@@ -38,6 +44,17 @@ const composedMap = mappedAgg.map<string>(x => x.toString());
38
44
expectType < AggregationCursor < string > > ( composedMap ) ;
39
45
expectType < string | null > ( await composedMap . next ( ) ) ;
40
46
expectType < string [ ] > ( await composedMap . toArray ( ) ) ;
47
+ const tschemaColl = db . collection < TSchema > ( 'test' ) ;
48
+ const changeStream = tschemaColl . watch ( ) ;
49
+ changeStream . on ( 'init' , doc => {
50
+ expectType < TSchema > ( doc ) ;
51
+ } ) ;
52
+ changeStream . on ( 'more' , doc => {
53
+ expectType < TSchema | undefined > ( doc ) ;
54
+ } ) ;
55
+ changeStream . on ( 'change' , doc => {
56
+ expectType < ChangeStreamDocument < TSchema > > ( doc ) ;
57
+ } ) ;
41
58
42
59
const builtCursor = coll . aggregate ( ) ;
43
60
// should allow string values for the out helper
0 commit comments