-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow validationOptions?: ValidationOptions in FormContextValues['register'] #1963
Comments
we need more details on this one, can you supply a codesandbox? |
@kotarella1110 looks like our register type is mismatching with |
@bluebill1049 I think we just need to fix the overload as follows: Lines 290 to 295 in 8bfbc05
- register<
- Element extends FieldElement<FormValues> = FieldElement<FormValues>
- >(): (ref: Element | null) => void;
- register<Element extends FieldElement<FormValues> = FieldElement<FormValues>>(
- validationOptions: ValidationOptions,
- ): (ref: Element | null) => void;
+ register<Element extends FieldElement<FormValues> = FieldElement<FormValues>>(
+ validationOptions?: ValidationOptions,
+ ): (ref: Element | null) => void; Do we need to apply this fix to both V5 and V6? |
Hmm, I can't get Codesandbox to surface strict null checking errors from TypeScript for some reason, but here's a link with the code that should surface complaints: https://codesandbox.io/s/react-hook-form-useform-template-j0zen?file=/src/index.tsxa |
Is your feature request related to a problem? Please describe.
I'd like to be able to call
register
with avalidationOptions
parameter of typeValidationOptions | undefined
.However, in TypeScript's strict type checking mode, this gives an unhappy complaint:
This is because
register
's first two overloads say that you can either have novalidationOptions
or a definedvalidationOptions
:I.e. you may not have an undefined
validationOptions
.Describe the solution you'd like
Could we make that second overload allow
?: ValidationOptions
?Describe alternatives you've considered
In my code, I could do something like
validationOptions ? register(validationOptions) : register()
, but that's a little less clean than calling directly.Additional context
You can see a real life code example in https://github.com/Codecademy/client-modules/pull/852 ✨
The text was updated successfully, but these errors were encountered: