@@ -21,7 +21,7 @@ import isBeforeFunc, { IsBeforeOptions } from "validator/lib/isBefore";
2121import isBICFunc from "validator/lib/isBIC" ;
2222import isBooleanFunc from "validator/lib/isBoolean" ;
2323import isBtcAddressFunc from "validator/lib/isBtcAddress" ;
24- import isByteLengthFunc from "validator/lib/isByteLength" ;
24+ import isByteLengthFunc , { IsByteLengthOptions } from "validator/lib/isByteLength" ;
2525import isCreditCardFunc from "validator/lib/isCreditCard" ;
2626import isCurrencyFunc from "validator/lib/isCurrency" ;
2727import isDataURIFunc from "validator/lib/isDataURI" ;
@@ -428,7 +428,7 @@ import isBeforeFuncEs, { IsBeforeOptions as IsBeforeOptionsEs } from "validator/
428428import isBICFuncEs from "validator/es/lib/isBIC" ;
429429import isBooleanFuncEs from "validator/es/lib/isBoolean" ;
430430import isBtcAddressFuncEs from "validator/es/lib/isBtcAddress" ;
431- import isByteLengthFuncEs from "validator/es/lib/isByteLength" ;
431+ import isByteLengthFuncEs , { IsByteLengthOptions as IsByteLengthOptionsEs } from "validator/es/lib/isByteLength" ;
432432import isCreditCardFuncEs from "validator/es/lib/isCreditCard" ;
433433import isCurrencyFuncEs from "validator/es/lib/isCurrency" ;
434434import isDataURIFuncEs from "validator/es/lib/isDataURI" ;
@@ -762,8 +762,17 @@ const any: any = null;
762762
763763 result = validator . isBoolean ( "sample" ) ;
764764
765- const isByteLengthOptions : validator . IsByteLengthOptions = { } ;
766- result = validator . isByteLength ( "sample" , isByteLengthOptions ) ;
765+ result = validator . isByteLength ( "sample" ) ;
766+ result = validator . isByteLength ( "sample" , { } ) ;
767+ result = validator . isByteLength ( "sample" , { min : 16 , max : 64 } satisfies IsByteLengthOptions ) ;
768+ result = validator . isByteLength ( "sample" , 16 ) ;
769+ result = validator . isByteLength ( "sample" , 16 , 64 ) ;
770+ // Both overloads happen to allow using exactly two argument, [str, number] & [str, object]
771+ // Hence if 2nd arg is of union type `number | object`, typechecking can pass.
772+ result = validator . isByteLength ( "sample" , result ? 16 : { min : 16 } ) ;
773+ // @ts -expect-error
774+ // Using 3rd arg here is problematic, without first ensuring that the 2nd argument is a number.
775+ result = validator . isByteLength ( "sample" , result ? 16 : { min : 16 } , 64 ) ;
767776
768777 const isCreditCardOptions : validator . IsCreditCardOptions = { } ;
769778 result = validator . isCreditCard ( "sample" ) ; // $ExpectType boolean
0 commit comments