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

Type inference error for meta.error from useField hook. #3994

Open
onlit opened this issue Sep 12, 2024 · 0 comments
Open

Type inference error for meta.error from useField hook. #3994

onlit opened this issue Sep 12, 2024 · 0 comments

Comments

@onlit
Copy link

onlit commented Sep 12, 2024

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'.

image

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant