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

Problem with InferType and cyclic dependency #1781

Open
azoriuss opened this issue Sep 22, 2022 · 0 comments
Open

Problem with InferType and cyclic dependency #1781

azoriuss opened this issue Sep 22, 2022 · 0 comments

Comments

@azoriuss
Copy link

Hi everyone
I'm using react-hook-form with yup in my project and i'm facing a little problem in a specific use case

Here's a simple schema with infered type

const schema = yup.object({
  field1: yup.string(),
  field2: yup.string()
})

interface FormInputs extends yup.InferType<typeof schema>{}

I found out that i can't use yup.object().shape(...) with InferType as it will return any (as mentioned here)

My problem come when I need to use yup.object().shape() with noSortEdge to avoid cyclic depency, like this :

const schema = yup.object().shape({
  field1: yup.string().when("field2", {
    is: (val) => !!val,
    then: (schema) => schema.required()
  }),
  field2: yup.string().when("field1", {
    is: (val) => !!val,
    then: (schema) => schema.required()
  })
},[['field1','field2']]);

In this case, yup.InferType is not working as expected, but on the other hand, I need to use shape to avoid cyclic dependency

Is there a way to keep InferType specificity and avoid cyclic dependency at the same time ?

Here is a sandbox

Let me know if you need more clarifications on my probem and thanks for your help (and for this library !)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant