File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -116,3 +116,28 @@ function gh15535() {
116116 expectType < string | null | undefined > ( doc . field3 ) ;
117117 expectType < string | null | undefined > ( doc . getField3 ( ) ) ;
118118}
119+
120+ async function gh15600 ( ) {
121+ // Base model with custom static method
122+ const baseSchema = new Schema (
123+ { name : String } ,
124+ {
125+ statics : {
126+ findByName ( name : string ) {
127+ return this . findOne ( { name } ) ;
128+ }
129+ }
130+ }
131+ ) ;
132+ const BaseModel = model ( 'Base' , baseSchema ) ;
133+
134+ const baseRes = await BaseModel . findByName ( 'test' ) ;
135+ expectType < string | null | undefined > ( baseRes ! . name ) ;
136+
137+ // Discriminator model inheriting base static methods
138+ const discriminatorSchema = new Schema ( { extra : String } ) ;
139+ const DiscriminatorModel = BaseModel . discriminator ( 'Discriminator' , discriminatorSchema ) ;
140+
141+ const res = await DiscriminatorModel . findByName ( 'test' ) ;
142+ expectType < string | null | undefined > ( res ! . name ) ;
143+ }
Original file line number Diff line number Diff line change @@ -435,7 +435,7 @@ declare module 'mongoose' {
435435 TQueryHelpers & ObtainSchemaGeneric < TDiscriminatorSchema , 'TQueryHelpers' > ,
436436 TInstanceMethods & ObtainSchemaGeneric < TDiscriminatorSchema , 'TInstanceMethods' > ,
437437 TVirtuals & ObtainSchemaGeneric < TDiscriminatorSchema , 'TVirtuals' >
438- > & ObtainSchemaGeneric < TDiscriminatorSchema , 'TStaticMethods' > ;
438+ > & ObtainSchemaGeneric < TSchema , 'TStaticMethods' > & ObtainSchemaGeneric < TDiscriminatorSchema , 'TStaticMethods' > ;
439439 discriminator < D > (
440440 name : string | number ,
441441 schema : Schema ,
You can’t perform that action at this time.
0 commit comments