Skip to content
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

[FieldError] - unexpected type error for Date property which is not nullable #8749

Closed
1 task done
I3enito opened this issue Jul 27, 2022 · 3 comments · Fixed by #8772
Closed
1 task done

[FieldError] - unexpected type error for Date property which is not nullable #8749

I3enito opened this issue Jul 27, 2022 · 3 comments · Fixed by #8772
Labels
question Further information is requested

Comments

@I3enito
Copy link

I3enito commented Jul 27, 2022

Version Number

7.33.1

Codesandbox/Expo snack

https://codesandbox.io/s/recursing-jang-9l8kqm?file=/src/App.tsx

Steps to reproduce

  1. Go to https://codesandbox.io/s/recursing-jang-9l8kqm?file=/src/App.tsx
  2. Check the App.tsx and check the type error for the mandatoryDateError

Expected behaviour

After upgrading to version 7.33.1 I got TS-errors because my DateInput expect a FieldError regardless if the Date is nullable or not. This is not an urgent issue but I thought it might be a edge case which has been discovered. Or perhaps I just don't understand why this behaviour makes sense.

Thanks for your work and the awesome library!

What browsers are you seeing the problem on?

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@bluebill1049
Copy link
Member

thanks for the issure report, type undefined is not assignable to FieldError https://codesandbox.io/s/focused-noyce-neh1zj?file=/src/App.tsx the latest update eliminated the need to use NestedValue to differentiate a nested object input vs a group of inputs. https://react-hook-form.com/ts#NestedValue This is a huge improvement for some use cases, as developers will no longer to implemented the NestedValue type anymore, however it does bring some limitations,s and moving forward I think it's worth taking those trade-offs, such as discriminating unions and perhaps your specific usage above as well. This will most likely not be reverted and moving forward to bring feature such as rules for useFieldArray.

@bluebill1049 bluebill1049 added the question Further information is requested label Jul 27, 2022
@I3enito
Copy link
Author

I3enito commented Jul 27, 2022

Thanks for the response. I honestly cannot completely follow your explanation as I didn't use NestedValue but that's fine. I was just surprised that there was another type generated for the error when using a Date. My solution is to just expect this type as well for my DateInput component.

interface InputDateProps<T> {
    className?: string
    type: 'date' | 'time'
    register: UseFormRegister<T>
    isDirty?: boolean
    defaultValue?: string
    label: string
    name: Path<T>
    required?: boolean
    error?: Merge<FieldError, FieldErrorsImpl<DeepRequired<Date>>> | FieldError
}

@bluebill1049
Copy link
Member

It's not that you are using NestedValue, the change was made so users don't have to use NestedValue anymore. related PR: https://github.com/react-hook-form/react-hook-form/pull/8527/files I will take a look at the issue this weekend and see if we can improve or else you will have to use the work around which you have provided above. 🙏

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants