@@ -22,7 +22,7 @@ const cursor = collection
2222 . min ( { age : 18 } )
2323 . maxAwaitTimeMS ( 1 )
2424 . maxTimeMS ( 1 )
25- . project ( { } )
25+ // .project({}) -> projections removes the types from the returned documents
2626 . returnKey ( true )
2727 . showRecordId ( true )
2828 . skip ( 1 )
@@ -31,6 +31,7 @@ const cursor = collection
3131
3232expectType < FindCursor < { foo : number } > > ( cursor ) ;
3333expectType < Readable > ( cursor . stream ( ) ) ;
34+ expectType < FindCursor < Document > > ( cursor . project ( { } ) ) ;
3435
3536collection . find ( ) . project ( { } ) ;
3637collection . find ( ) . project ( { notExistingField : 1 } ) ;
@@ -118,7 +119,7 @@ interface PublicMeme {
118119 likes : number ;
119120 someRandomProp : boolean ; // Projection makes no enforcement on anything
120121 // the convenience parameter project<X>() allows you to define a return type,
121- // otherwise projections returns your schema
122+ // otherwise projections returns generic document
122123}
123124
124125const publicMemeProjection = {
@@ -132,18 +133,14 @@ const memeCollection = new Db(new MongoClient(''), '').collection<InternalMeme>(
132133expectType < PublicMeme [ ] > (
133134 await memeCollection
134135 . find ( { _id : { $in : [ ] } } )
135- . sort ( { _id : - 1 } )
136- . limit ( 3 )
137136 . project < PublicMeme > ( publicMemeProjection ) // <== Argument of type T is not assignable to parameter of type U
138137 . toArray ( )
139138) ;
140139
141- // Returns you're untouched schema when no override given
142- expectType < InternalMeme [ ] > (
140+ // Returns generic document when no override given
141+ expectNotType < InternalMeme [ ] > (
143142 await memeCollection
144143 . find ( { _id : { $in : [ ] } } )
145- . sort ( { _id : - 1 } )
146- . limit ( 3 )
147144 . project ( publicMemeProjection ) // <== Argument of type T is not assignable to parameter of type U
148145 . toArray ( )
149146) ;
@@ -153,8 +150,6 @@ expectType<Document[]>(
153150 await new Db ( new MongoClient ( '' ) , '' )
154151 . collection ( 'memes' )
155152 . find ( { _id : { $in : [ ] } } )
156- . sort ( { _id : - 1 } )
157- . limit ( 3 )
158153 . project ( publicMemeProjection ) // <== Argument of type T is not assignable to parameter of type U
159154 . toArray ( )
160155) ;
0 commit comments