@@ -586,8 +586,14 @@ S.asSchema(S.struct({ a: S.optional(S.never, { exact: true }) }))
586
586
// $ExpectType struct<{ a: PropertySignature<"?:", never, never, "?:", never, never>; }>
587
587
S . struct ( { a : S . optional ( S . never , { exact : true } ) } )
588
588
589
+ // $ExpectType Schema<{ readonly a?: string; }, { readonly a?: string; }, never>
590
+ S . asSchema ( S . struct ( { a : S . string . pipe ( S . optional ( { exact : true } ) ) } ) )
591
+
592
+ // $ExpectType struct<{ a: PropertySignature<"?:", string, never, "?:", string, never>; }>
593
+ S . struct ( { a : S . string . pipe ( S . optional ( { exact : true } ) ) } )
594
+
589
595
// ---------------------------------------------
590
- // optional
596
+ // optional()
591
597
// ---------------------------------------------
592
598
593
599
// $ExpectType Schema<{ readonly a: string; readonly b: number; readonly c?: boolean | undefined; }, { readonly a: string; readonly b: number; readonly c?: boolean | undefined; }, never>
@@ -608,6 +614,12 @@ S.asSchema(S.struct({ a: S.optional(S.never) }))
608
614
// $ExpectType struct<{ a: PropertySignature<"?:", undefined, never, "?:", undefined, never>; }>
609
615
S . struct ( { a : S . optional ( S . never ) } )
610
616
617
+ // $ExpectType Schema<{ readonly a?: string | undefined; }, { readonly a?: string | undefined; }, never>
618
+ S . asSchema ( S . struct ( { a : S . string . pipe ( S . optional ( ) ) } ) )
619
+
620
+ // $ExpectType struct<{ a: PropertySignature<"?:", string | undefined, never, "?:", string | undefined, never>; }>
621
+ S . struct ( { a : S . string . pipe ( S . optional ( ) ) } )
622
+
611
623
// ---------------------------------------------
612
624
// optional { exact: true, default: () => A }
613
625
// ---------------------------------------------
@@ -640,9 +652,15 @@ S.struct({
640
652
c : S . optional ( S . NumberFromString , { exact : true , default : ( ) => 0 } )
641
653
} )
642
654
643
- // @ts -expect-error
655
+ // $ExpectType struct<{ a: PropertySignature<":", "a" | "b", never, "?:", "a" | "b", never>; }>
644
656
S . struct ( { a : S . optional ( S . literal ( "a" , "b" ) , { default : ( ) => "a" , exact : true } ) } )
645
657
658
+ // $ExpectType Schema<{ readonly a: "a" | "b"; }, { readonly a?: "a" | "b"; }, never>
659
+ S . asSchema ( S . struct ( { a : S . literal ( "a" , "b" ) . pipe ( S . optional ( { default : ( ) => "a" , exact : true } ) ) } ) )
660
+
661
+ // $ExpectType struct<{ a: PropertySignature<":", "a" | "b", never, "?:", "a" | "b", never>; }>
662
+ S . struct ( { a : S . literal ( "a" , "b" ) . pipe ( S . optional ( { default : ( ) => "a" , exact : true } ) ) } )
663
+
646
664
// ---------------------------------------------
647
665
// optional { default: () => A }
648
666
// ---------------------------------------------
@@ -659,9 +677,15 @@ S.asSchema(S.struct({ a: S.string, b: S.number, c: S.optional(S.NumberFromString
659
677
// $ExpectType struct<{ a: $string; b: $number; c: PropertySignature<":", number, never, "?:", string | undefined, never>; }>
660
678
S . struct ( { a : S . string , b : S . number , c : S . optional ( S . NumberFromString , { default : ( ) => 0 } ) } )
661
679
662
- // @ts -expect-error
680
+ // $ExpectType struct<{ a: PropertySignature<":", "a" | "b", never, "?:", "a" | "b" | undefined, never>; }>
663
681
S . struct ( { a : S . optional ( S . literal ( "a" , "b" ) , { default : ( ) => "a" } ) } )
664
682
683
+ // $ExpectType Schema<{ readonly a: "a" | "b"; }, { readonly a?: "a" | "b" | undefined; }, never>
684
+ S . asSchema ( S . struct ( { a : S . literal ( "a" , "b" ) . pipe ( S . optional ( { default : ( ) => "a" as const } ) ) } ) )
685
+
686
+ // $ExpectType struct<{ a: PropertySignature<":", "a" | "b", never, "?:", "a" | "b" | undefined, never>; }>
687
+ S . struct ( { a : S . literal ( "a" , "b" ) . pipe ( S . optional ( { default : ( ) => "a" as const } ) ) } )
688
+
665
689
// ---------------------------------------------
666
690
// optional { nullable: true, default: () => A }
667
691
// ---------------------------------------------
@@ -678,9 +702,15 @@ S.asSchema(S.struct({ a: S.optional(S.NumberFromString, { exact: true, nullable:
678
702
// $ExpectType struct<{ a: PropertySignature<":", number, never, "?:", string | null, never>; }>
679
703
S . struct ( { a : S . optional ( S . NumberFromString , { exact : true , nullable : true , default : ( ) => 0 } ) } )
680
704
681
- // @ts -expect-error
705
+ // $ExpectType struct<{ a: PropertySignature<":", "a" | "b", never, "?:", "a" | "b" | null | undefined, never>; }>
682
706
S . struct ( { a : S . optional ( S . literal ( "a" , "b" ) , { default : ( ) => "a" , nullable : true } ) } )
683
707
708
+ // $ExpectType Schema<{ readonly a: "a" | "b"; }, { readonly a?: "a" | "b" | null | undefined; }, never>
709
+ S . asSchema ( S . struct ( { a : S . literal ( "a" , "b" ) . pipe ( S . optional ( { default : ( ) => "a" , nullable : true } ) ) } ) )
710
+
711
+ // $ExpectType struct<{ a: PropertySignature<":", "a" | "b", never, "?:", "a" | "b" | null | undefined, never>; }>
712
+ S . struct ( { a : S . literal ( "a" , "b" ) . pipe ( S . optional ( { default : ( ) => "a" , nullable : true } ) ) } )
713
+
684
714
// ---------------------------------------------
685
715
// optional { exact: true, as: "Option" }
686
716
// ---------------------------------------------
@@ -705,6 +735,12 @@ S.struct({
705
735
c : S . optional ( S . NumberFromString , { exact : true , as : "Option" } )
706
736
} )
707
737
738
+ // $ExpectType Schema<{ readonly a: Option<string>; }, { readonly a?: string; }, never>
739
+ S . asSchema ( S . struct ( { a : S . string . pipe ( S . optional ( { exact : true , as : "Option" } ) ) } ) )
740
+
741
+ // $ExpectType struct<{ a: PropertySignature<":", Option<string>, never, "?:", string, never>; }>
742
+ S . struct ( { a : S . string . pipe ( S . optional ( { exact : true , as : "Option" } ) ) } )
743
+
708
744
// ---------------------------------------------
709
745
// optional { as: "Option" }
710
746
// ---------------------------------------------
@@ -721,6 +757,12 @@ S.asSchema(S.struct({ a: S.string, b: S.number, c: S.optional(S.NumberFromString
721
757
// $ExpectType struct<{ a: $string; b: $number; c: PropertySignature<":", Option<number>, never, "?:", string | undefined, never>; }>
722
758
S . struct ( { a : S . string , b : S . number , c : S . optional ( S . NumberFromString , { as : "Option" } ) } )
723
759
760
+ // $ExpectType Schema<{ readonly a: Option<string>; }, { readonly a?: string | undefined; }, never>
761
+ S . asSchema ( S . struct ( { a : S . string . pipe ( S . optional ( { as : "Option" } ) ) } ) )
762
+
763
+ // $ExpectType struct<{ a: PropertySignature<":", Option<string>, never, "?:", string | undefined, never>; }>
764
+ S . struct ( { a : S . string . pipe ( S . optional ( { as : "Option" } ) ) } )
765
+
724
766
// ---------------------------------------------
725
767
// optional { nullable: true, as: "Option" }
726
768
// ---------------------------------------------
@@ -731,12 +773,28 @@ S.asSchema(S.struct({ a: S.optional(S.NumberFromString, { nullable: true, as: "O
731
773
// $ExpectType struct<{ a: PropertySignature<":", Option<number>, never, "?:", string | null | undefined, never>; }>
732
774
S . struct ( { a : S . optional ( S . NumberFromString , { nullable : true , as : "Option" } ) } )
733
775
776
+ // $ExpectType Schema<{ readonly a: Option<string>; }, { readonly a?: string | null | undefined; }, never>
777
+ S . asSchema ( S . struct ( { a : S . string . pipe ( S . optional ( { nullable : true , as : "Option" } ) ) } ) )
778
+
779
+ // $ExpectType struct<{ a: PropertySignature<":", Option<string>, never, "?:", string | null | undefined, never>; }>
780
+ S . struct ( { a : S . string . pipe ( S . optional ( { nullable : true , as : "Option" } ) ) } )
781
+
782
+ // ---------------------------------------------
783
+ // optional { exact: true, nullable: true, as: "Option" }
784
+ // ---------------------------------------------
785
+
734
786
// $ExpectType Schema<{ readonly a: Option<number>; }, { readonly a?: string | null; }, never>
735
787
S . asSchema ( S . struct ( { a : S . optional ( S . NumberFromString , { exact : true , nullable : true , as : "Option" } ) } ) )
736
788
737
789
// $ExpectType struct<{ a: PropertySignature<":", Option<number>, never, "?:", string | null, never>; }>
738
790
S . struct ( { a : S . optional ( S . NumberFromString , { exact : true , nullable : true , as : "Option" } ) } )
739
791
792
+ // $ExpectType Schema<{ readonly a: Option<string>; }, { readonly a?: string | null; }, never>
793
+ S . asSchema ( S . struct ( { a : S . string . pipe ( S . optional ( { exact : true , nullable : true , as : "Option" } ) ) } ) )
794
+
795
+ // $ExpectType struct<{ a: PropertySignature<":", Option<string>, never, "?:", string | null, never>; }>
796
+ S . struct ( { a : S . string . pipe ( S . optional ( { exact : true , nullable : true , as : "Option" } ) ) } )
797
+
740
798
// ---------------------------------------------
741
799
// pick
742
800
// ---------------------------------------------
0 commit comments