@@ -372,50 +372,50 @@ export function autoTypedSchema() {
372
372
}
373
373
374
374
type TestSchemaType = {
375
- string1 ?: string ;
376
- string2 ?: string ;
377
- string3 ?: string ;
378
- string4 ?: string ;
375
+ string1 ?: string | null ;
376
+ string2 ?: string | null ;
377
+ string3 ?: string | null ;
378
+ string4 ?: string | null ;
379
379
string5 : string ;
380
- number1 ?: number ;
381
- number2 ?: number ;
382
- number3 ?: number ;
383
- number4 ?: number ;
380
+ number1 ?: number | null ;
381
+ number2 ?: number | null ;
382
+ number3 ?: number | null ;
383
+ number4 ?: number | null ;
384
384
number5 : number ;
385
- date1 ?: Date ;
386
- date2 ?: Date ;
387
- date3 ?: Date ;
388
- date4 ?: Date ;
385
+ date1 ?: Date | null ;
386
+ date2 ?: Date | null ;
387
+ date3 ?: Date | null ;
388
+ date4 ?: Date | null ;
389
389
date5 : Date ;
390
- buffer1 ?: Buffer ;
391
- buffer2 ?: Buffer ;
392
- buffer3 ?: Buffer ;
393
- buffer4 ?: Buffer ;
394
- boolean1 ?: boolean ;
395
- boolean2 ?: boolean ;
396
- boolean3 ?: boolean ;
397
- boolean4 ?: boolean ;
390
+ buffer1 ?: Buffer | null ;
391
+ buffer2 ?: Buffer | null ;
392
+ buffer3 ?: Buffer | null ;
393
+ buffer4 ?: Buffer | null ;
394
+ boolean1 ?: boolean | null ;
395
+ boolean2 ?: boolean | null ;
396
+ boolean3 ?: boolean | null ;
397
+ boolean4 ?: boolean | null ;
398
398
boolean5 : boolean ;
399
- mixed1 ?: any ;
400
- mixed2 ?: any ;
401
- mixed3 ?: any ;
402
- objectId1 ?: Types . ObjectId ;
403
- objectId2 ?: Types . ObjectId ;
404
- objectId3 ?: Types . ObjectId ;
405
- customSchema ?: Int8 ;
406
- map1 ?: Map < string , string > ;
407
- map2 ?: Map < string , number > ;
399
+ mixed1 ?: any | null ;
400
+ mixed2 ?: any | null ;
401
+ mixed3 ?: any | null ;
402
+ objectId1 ?: Types . ObjectId | null ;
403
+ objectId2 ?: Types . ObjectId | null ;
404
+ objectId3 ?: Types . ObjectId | null ;
405
+ customSchema ?: Int8 | null ;
406
+ map1 ?: Map < string , string > | null ;
407
+ map2 ?: Map < string , number > | null ;
408
408
array1 : string [ ] ;
409
409
array2 : any [ ] ;
410
410
array3 : any [ ] ;
411
411
array4 : any [ ] ;
412
412
array5 : any [ ] ;
413
413
array6 : string [ ] ;
414
- array7 ?: string [ ] ;
415
- array8 ?: string [ ] ;
416
- decimal1 ?: Types . Decimal128 ;
417
- decimal2 ?: Types . Decimal128 ;
418
- decimal3 ?: Types . Decimal128 ;
414
+ array7 ?: string [ ] | null ;
415
+ array8 ?: string [ ] | null ;
416
+ decimal1 ?: Types . Decimal128 | null ;
417
+ decimal2 ?: Types . Decimal128 | null ;
418
+ decimal3 ?: Types . Decimal128 | null ;
419
419
} ;
420
420
421
421
const TestSchema = new Schema ( {
@@ -546,17 +546,17 @@ export function autoTypedSchema() {
546
546
export type AutoTypedSchemaType = {
547
547
schema : {
548
548
userName : string ;
549
- description ?: string ;
549
+ description ?: string | null ;
550
550
nested ?: {
551
551
age : number ;
552
- hobby ?: string
553
- } ,
554
- favoritDrink ?: 'Tea' | 'Coffee' ,
552
+ hobby ?: string | null
553
+ } | null ,
554
+ favoritDrink ?: 'Tea' | 'Coffee' | null ,
555
555
favoritColorMode : 'dark' | 'light'
556
- friendID ?: Types . ObjectId ;
556
+ friendID ?: Types . ObjectId | null ;
557
557
nestedArray : Types . DocumentArray < {
558
558
date : Date ;
559
- messages ?: number ;
559
+ messages ?: number | null ;
560
560
} >
561
561
}
562
562
, statics : {
@@ -634,7 +634,7 @@ function gh12003() {
634
634
type TSchemaOptions = ResolveSchemaOptions < ObtainSchemaGeneric < typeof BaseSchema , 'TSchemaOptions' > > ;
635
635
expectType < 'type' > ( { } as TSchemaOptions [ 'typeKey' ] ) ;
636
636
637
- expectType < { name ?: string } > ( { } as BaseSchemaType ) ;
637
+ expectType < { name ?: string | null } > ( { } as BaseSchemaType ) ;
638
638
}
639
639
640
640
function gh11987 ( ) {
@@ -670,7 +670,7 @@ function gh12030() {
670
670
}
671
671
] > ;
672
672
expectType < {
673
- username ?: string
673
+ username ?: string | null
674
674
} [ ] > ( { } as A ) ;
675
675
676
676
type B = ObtainDocumentType < {
@@ -682,13 +682,13 @@ function gh12030() {
682
682
} > ;
683
683
expectType < {
684
684
users : {
685
- username ?: string
685
+ username ?: string | null
686
686
} [ ] ;
687
687
} > ( { } as B ) ;
688
688
689
689
expectType < {
690
690
users : {
691
- username ?: string
691
+ username ?: string | null
692
692
} [ ] ;
693
693
} > ( { } as InferSchemaType < typeof Schema1 > ) ;
694
694
@@ -710,7 +710,7 @@ function gh12030() {
710
710
expectType < {
711
711
users : Types . DocumentArray < {
712
712
credit : number ;
713
- username ?: string ;
713
+ username ?: string | null ;
714
714
} > ;
715
715
} > ( { } as InferSchemaType < typeof Schema3 > ) ;
716
716
@@ -719,7 +719,7 @@ function gh12030() {
719
719
data : { type : { role : String } , default : { } }
720
720
} ) ;
721
721
722
- expectType < { data : { role ?: string } } > ( { } as InferSchemaType < typeof Schema4 > ) ;
722
+ expectType < { data : { role ?: string | null } } > ( { } as InferSchemaType < typeof Schema4 > ) ;
723
723
724
724
const Schema5 = new Schema ( {
725
725
data : { type : { role : Object } , default : { } }
@@ -744,7 +744,7 @@ function gh12030() {
744
744
track ?: {
745
745
backupCount : number ;
746
746
count : number ;
747
- } ;
747
+ } | null ;
748
748
} > ( { } as InferSchemaType < typeof Schema6 > ) ;
749
749
750
750
}
@@ -821,7 +821,7 @@ function gh12450() {
821
821
} ) ;
822
822
823
823
expectType < {
824
- user ?: Types . ObjectId ;
824
+ user ?: Types . ObjectId | null ;
825
825
} > ( { } as InferSchemaType < typeof ObjectIdSchema > ) ;
826
826
827
827
const Schema2 = new Schema ( {
@@ -836,14 +836,14 @@ function gh12450() {
836
836
decimalValue : { type : Schema . Types . Decimal128 }
837
837
} ) ;
838
838
839
- expectType < { createdAt : Date , decimalValue ?: Types . Decimal128 } > ( { } as InferSchemaType < typeof Schema3 > ) ;
839
+ expectType < { createdAt : Date , decimalValue ?: Types . Decimal128 | null } > ( { } as InferSchemaType < typeof Schema3 > ) ;
840
840
841
841
const Schema4 = new Schema ( {
842
842
createdAt : { type : Date } ,
843
843
decimalValue : { type : Schema . Types . Decimal128 }
844
844
} ) ;
845
845
846
- expectType < { createdAt ?: Date , decimalValue ?: Types . Decimal128 } > ( { } as InferSchemaType < typeof Schema4 > ) ;
846
+ expectType < { createdAt ?: Date | null , decimalValue ?: Types . Decimal128 | null } > ( { } as InferSchemaType < typeof Schema4 > ) ;
847
847
}
848
848
849
849
function gh12242 ( ) {
@@ -867,13 +867,13 @@ function testInferTimestamps() {
867
867
// an error "Parameter type { createdAt: Date; updatedAt: Date; name?: string | undefined; }
868
868
// is not identical to argument type { createdAt: NativeDate; updatedAt: NativeDate; } &
869
869
// { name?: string | undefined; }"
870
- expectType < { createdAt : Date , updatedAt : Date } & { name ?: string } > ( { } as WithTimestamps ) ;
870
+ expectType < { createdAt : Date , updatedAt : Date } & { name ?: string | null } > ( { } as WithTimestamps ) ;
871
871
872
872
const schema2 = new Schema ( {
873
873
name : String
874
874
} , {
875
875
timestamps : true ,
876
- methods : { myName ( ) : string | undefined {
876
+ methods : { myName ( ) : string | undefined | null {
877
877
return this . name ;
878
878
} }
879
879
} ) ;
@@ -883,7 +883,7 @@ function testInferTimestamps() {
883
883
// an error "Parameter type { createdAt: Date; updatedAt: Date; name?: string | undefined; }
884
884
// is not identical to argument type { createdAt: NativeDate; updatedAt: NativeDate; } &
885
885
// { name?: string | undefined; }"
886
- expectType < { name ?: string } > ( { } as WithTimestamps2 ) ;
886
+ expectType < { name ?: string | null } > ( { } as WithTimestamps2 ) ;
887
887
}
888
888
889
889
function gh12431 ( ) {
@@ -893,25 +893,25 @@ function gh12431() {
893
893
} ) ;
894
894
895
895
type Example = InferSchemaType < typeof testSchema > ;
896
- expectType < { testDate ?: Date , testDecimal ?: Types . Decimal128 } > ( { } as Example ) ;
896
+ expectType < { testDate ?: Date | null , testDecimal ?: Types . Decimal128 | null } > ( { } as Example ) ;
897
897
}
898
898
899
899
async function gh12593 ( ) {
900
900
const testSchema = new Schema ( { x : { type : Schema . Types . UUID } } ) ;
901
901
902
902
type Example = InferSchemaType < typeof testSchema > ;
903
- expectType < { x ?: Buffer } > ( { } as Example ) ;
903
+ expectType < { x ?: Buffer | null } > ( { } as Example ) ;
904
904
905
905
const Test = model ( 'Test' , testSchema ) ;
906
906
907
907
const doc = await Test . findOne ( { x : '4709e6d9-61fd-435e-b594-d748eb196d8f' } ) . orFail ( ) ;
908
- expectType < Buffer | undefined > ( doc . x ) ;
908
+ expectType < Buffer | undefined | null > ( doc . x ) ;
909
909
910
910
const doc2 = new Test ( { x : '4709e6d9-61fd-435e-b594-d748eb196d8f' } ) ;
911
- expectType < Buffer | undefined > ( doc2 . x ) ;
911
+ expectType < Buffer | undefined | null > ( doc2 . x ) ;
912
912
913
913
const doc3 = await Test . findOne ( { } ) . orFail ( ) . lean ( ) ;
914
- expectType < Buffer | undefined > ( doc3 . x ) ;
914
+ expectType < Buffer | undefined | null > ( doc3 . x ) ;
915
915
916
916
const arrSchema = new Schema ( { arr : [ { type : Schema . Types . UUID } ] } ) ;
917
917
@@ -978,7 +978,7 @@ function gh12611() {
978
978
expectType < {
979
979
description : string ;
980
980
skills : Types . ObjectId [ ] ;
981
- anotherField ?: string ;
981
+ anotherField ?: string | null ;
982
982
} > ( { } as Props ) ;
983
983
}
984
984
@@ -1181,7 +1181,7 @@ function gh13702() {
1181
1181
function gh13780 ( ) {
1182
1182
const schema = new Schema ( { num : Schema . Types . BigInt } ) ;
1183
1183
type InferredType = InferSchemaType < typeof schema > ;
1184
- expectType < bigint | undefined > ( null as unknown as InferredType [ 'num' ] ) ;
1184
+ expectType < bigint | undefined | null > ( null as unknown as InferredType [ 'num' ] ) ;
1185
1185
}
1186
1186
1187
1187
function gh13800 ( ) {
0 commit comments