@@ -702,3 +702,38 @@ function gh12030() {
702
702
} > ( { } as InferSchemaType < typeof Schema6 > ) ;
703
703
704
704
}
705
+
706
+ function pluginOptions ( ) {
707
+ interface SomePluginOptions {
708
+ option1 ?: string ;
709
+ option2 : number ;
710
+ }
711
+
712
+ function pluginFunction ( schema : Schema < any > , options : SomePluginOptions ) {
713
+ return ; // empty function, to satisfy lint option
714
+ }
715
+
716
+ const schema = new Schema ( { } ) ;
717
+ expectType < Schema < any > > ( schema . plugin ( pluginFunction ) ) ; // test that chaining would be possible
718
+
719
+ // could not add strict tests that the parameters are inferred correctly, because i dont know how this would be done in tsd
720
+
721
+ // test basic inferrence
722
+ expectError ( schema . plugin ( pluginFunction , { } ) ) ; // should error because "option2" is not optional
723
+ schema . plugin ( pluginFunction , { option2 : 0 } ) ;
724
+ schema . plugin ( pluginFunction , { option1 : 'string' , option2 : 1 } ) ;
725
+ expectError ( schema . plugin ( pluginFunction , { option1 : 'string' } ) ) ; // should error because "option2" is not optional
726
+ expectError ( schema . plugin ( pluginFunction , { option2 : 'string' } ) ) ; // should error because "option2" type is "number"
727
+ expectError ( schema . plugin ( pluginFunction , { option1 : 0 } ) ) ; // should error because "option1" type is "string"
728
+
729
+ // test plugins without options defined
730
+ function pluginFunction2 ( schema : Schema < any > ) {
731
+ return ; // empty function, to satisfy lint option
732
+ }
733
+ schema . plugin ( pluginFunction2 ) ;
734
+ expectError ( schema . plugin ( pluginFunction2 , { } ) ) ; // should error because no options argument is defined
735
+
736
+ // test overwriting options
737
+ schema . plugin < any , SomePluginOptions > ( pluginFunction2 , { option2 : 0 } ) ;
738
+ expectError ( schema . plugin < any , SomePluginOptions > ( pluginFunction2 , { } ) ) ; // should error because "option2" is not optional
739
+ }
0 commit comments