Type inference error for meta.error from useField hook. #3994
Open
Description
Bug report
Current Behavior
Given the Yup
validation schema for the jobLevel
field. The error could be either a string errors.jobLevel
or errors.jobLevel?.id
but I get an error Property 'id' does not exist on type 'never'.
Expected behavior
Correct type inference for typescript to handle both string and object types.
Reproducible example
Validation schema can be found in App.tsx
. If you look at Field.tsx
example you'd be able to see the type error.
https://codesandbox.io/p/sandbox/formik-type-issue-jhgpj3
Suggested solution(s)
Additional context
Your environment
Software | Version(s) |
---|---|
Formik | ^2.2.9 |
React | 18.3.1 |
TypeScript | ^5.3.3 |
Browser | Brave v1.69.168 |
npm/Yarn | Yarn 1.22.22 |
Operating System | Windows |