File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
13
13
UpdateQuery ,
14
14
UpdateQueryKnownOnly ,
15
15
QuerySelector ,
16
+ InferRawDocType ,
16
17
InferSchemaType ,
17
18
ProjectionFields ,
18
19
QueryOptions ,
@@ -710,3 +711,17 @@ function gh14841() {
710
711
$expr : { $lt : [ { $size : '$owners' } , 10 ] }
711
712
} ;
712
713
}
714
+
715
+ async function gh15526 ( ) {
716
+ const userSchemaDefinition = { name : String , age : Number } as const ;
717
+ const UserModel = model ( 'User' , new Schema ( userSchemaDefinition ) ) ;
718
+ type UserType = InferRawDocType < typeof userSchemaDefinition > ;
719
+
720
+ const selection = [ 'name' ] as const satisfies readonly ( keyof UserType ) [ ] ;
721
+
722
+ const u1 = await UserModel . findOne ( )
723
+ . select < Pick < UserType , ( typeof selection ) [ number ] > > ( selection )
724
+ . orFail ( ) ;
725
+ expectType < string | undefined | null > ( u1 . name ) ;
726
+ expectError ( u1 . age ) ;
727
+ }
Original file line number Diff line number Diff line change @@ -758,7 +758,7 @@ declare module 'mongoose' {
758
758
759
759
/** Specifies which document fields to include or exclude (also known as the query "projection") */
760
760
select < RawDocTypeOverride extends { [ P in keyof RawDocType ] ?: any } = { } > (
761
- arg : string | string [ ] | Record < string , number | boolean | string | object >
761
+ arg : string | readonly string [ ] | Record < string , number | boolean | string | object >
762
762
) : QueryWithHelpers <
763
763
IfEquals <
764
764
RawDocTypeOverride ,
You can’t perform that action at this time.
0 commit comments