jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
34k stars 2.79k forks source link

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

Open onlit opened 2 months ago

onlit commented 2 months ago

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