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 {
1313 UpdateQuery ,
1414 UpdateQueryKnownOnly ,
1515 QuerySelector ,
16+ InferRawDocType ,
1617 InferSchemaType ,
1718 ProjectionFields ,
1819 QueryOptions ,
@@ -710,3 +711,17 @@ function gh14841() {
710711 $expr : { $lt : [ { $size : '$owners' } , 10 ] }
711712 } ;
712713}
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' {
758758
759759 /** Specifies which document fields to include or exclude (also known as the query "projection") */
760760 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 >
762762 ) : QueryWithHelpers <
763763 IfEquals <
764764 RawDocTypeOverride ,
You can’t perform that action at this time.
0 commit comments