Skip to content

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

Open
@onlit

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

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

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions