@@ -1231,7 +1231,7 @@ async function gh13797() {
1231
1231
} } } ) ;
1232
1232
}
1233
1233
1234
- async function gh14028 ( ) {
1234
+ function gh14028_methods ( ) {
1235
1235
// Methods that have access to `this` should have access to typing of other methods on the schema
1236
1236
interface IUser {
1237
1237
firstName : string ;
@@ -1296,14 +1296,17 @@ async function gh14028() {
1296
1296
user2 . fullName ( ) ;
1297
1297
user2 . isAdult ( ) ;
1298
1298
1299
+ type UserModelWithoutMethods = Model < IUser > ;
1299
1300
// Skip InstanceMethods
1300
- const schema3 = new Schema < IUser , UserModel > ( {
1301
+ const schema3 = new Schema < IUser , UserModelWithoutMethods > ( {
1301
1302
firstName : { type : String , required : true } ,
1302
1303
lastName : { type : String , required : true } ,
1303
1304
age : { type : Number , required : true }
1304
1305
} , {
1305
1306
methods : {
1306
1307
fullName ( ) {
1308
+ // Expect methods to still have access to `this` type
1309
+ expectType < string > ( this . firstName ) ;
1307
1310
// As InstanceMethods type is not specified, expect type of this.fullName to be undefined
1308
1311
expectError < IUserMethods [ 'fullName' ] > ( this . fullName ) ;
1309
1312
return this . firstName + ' ' + this . lastName ;
@@ -1315,3 +1318,36 @@ async function gh14028() {
1315
1318
const user3 = new User3 ( { firstName : 'John' , lastName : 'Doe' , age : 20 } ) ;
1316
1319
expectError < string > ( user3 . fullName ( ) ) ;
1317
1320
}
1321
+
1322
+ function gh14028_statics ( ) {
1323
+ // Methods that have access to `this` should have access to typing of other methods on the schema
1324
+ interface IUser {
1325
+ firstName : string ;
1326
+ lastName : string ;
1327
+ age : number ;
1328
+ }
1329
+ interface IUserStatics {
1330
+ createWithFullName ( name : string ) : Promise < IUser > ;
1331
+ }
1332
+ type UserModel = Model < IUser , { } > ;
1333
+
1334
+ // Define statics on schema
1335
+ const schema = new Schema < IUser , UserModel , { } , { } , { } , IUserStatics > ( {
1336
+ firstName : { type : String , required : true } ,
1337
+ lastName : { type : String , required : true } ,
1338
+ age : { type : Number , required : true }
1339
+ } , {
1340
+ statics : {
1341
+ createWithFullName ( name : string ) {
1342
+ expectType < IUserStatics [ 'createWithFullName' ] > ( schema . statics . createWithFullName ) ;
1343
+ expectType < UserModel [ 'create' ] > ( this . create ) ;
1344
+
1345
+ const [ firstName , lastName ] = name . split ( ' ' ) ;
1346
+ return this . create ( { firstName, lastName } ) ;
1347
+ }
1348
+ }
1349
+ } ) ;
1350
+
1351
+ // Trigger type assertions inside statics
1352
+ schema . statics . createWithFullName ( 'John Doe' ) ;
1353
+ }
0 commit comments