Skip to content

issue: yupResolver inferred type mismatch against it's own schema for any optional fields #807

@JuliusSaik

Description

@JuliusSaik

Version Number

5.2.1

Codesandbox/Expo snack

https://codesandbox.io/p/sandbox/fancy-architecture-xkm2g4

Steps to reproduce

  1. Go to the codesandbox demo
  2. Update the dependencies if needed
  3. Hover over the typescript error for the resolver
  4. You'll see the error:
    Type '{ query?: string | undefined; }' is not assignable to type '{ query: string | undefined; }'

Expected behaviour

Since this is inferring the type from the exact schema I declare with the yup object, I'd assume it would not have any mismatch or asigning errors, but as you can see from the demo:
Type '{ query?: string | undefined; }' is not assignable to type '{ query: string | undefined;
Using .notRequired() creates the same problem.

My requirements do need this value to specifically be able to be undefined, but the only way you can achieve that is to omit the key entirely, but I still need some sort of validation if it's there and defined.

P.S if this is more of a yup related problem then I can repost it on their github

What browsers are you seeing the problem on?

Chrome

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions