Giter Site home page Giter Site logo

Comments (23)

JStatik avatar JStatik commented on June 18, 2024 7

You can try this option:

...
    } = useForm({
        defaultValues: stripNulls(defaultValues) as DefaultValues<T>,
        resolver: yupResolver(schema) as unknown as Resolver<T>,
        mode: validateMode,
    });

from resolvers.

cgallo-multiplica avatar cgallo-multiplica commented on June 18, 2024 5

If it worked before and now it doesn't, it's a problem with the library, not how we're using it.

from resolvers.

supersnager avatar supersnager commented on June 18, 2024 4

I think the issue start appearing after this commit: 918d72f, but IMHO the resolver is fine, but problem lies in RHF typings. I reported it here: react-hook-form/react-hook-form#11686

from resolvers.

egdelwonk avatar egdelwonk commented on June 18, 2024 2

Still facing this issue as well.

Node: v20.12.2

{
  "yup": "^1.4.0",
  "typescript": "~5.4.2",
  "@hookform/resolvers": "^3.3.4",
  "react-hook-form": "^7.51.3",
}

from resolvers.

tjelvar-chromaway avatar tjelvar-chromaway commented on June 18, 2024 1

i'm able to use @hookform/resolvers: 3.3.3 with yup: 0.32.11 but with any newer version of yup than that, it breaks. Just basing off of the quick start yup example https://www.npmjs.com/package/@hookform/resolvers#yup (but without using .shape(...). With it it does not work with these versions either.

edit: solved my issue #648 (comment)

from resolvers.

yamatsum avatar yamatsum commented on June 18, 2024 1

@greeeg
That post was posted by me with the same content.

from resolvers.

tjelvar-chromaway avatar tjelvar-chromaway commented on June 18, 2024 1

Okay now i'm gonna sound like generic tech support, but did you try shutting it off and turning it back on again?

I removed my node_modules and re-installed all my dependencies and what gave me errors before no longer does.

"dependencies": {
  "react-hook-form": "^7.49.2",
  "yup": "1.3.3",
  "@hookform/resolvers": "^3.3.3",
  ...
}

now i have

import * as yup from "yup";

export const generateSchema = () =>
  yup
    .object({
      obj: yup.object({
        prop1: yup.string().required(),
        prop2: yup.string().required(),
      }),
    })
    .required();

and i'm able to use it like

  const methods = useForm({
    resolver: yupResolver(generateSchema()),
  });

Where ts was previously complaining about generateSchema() missing fields it is no longer doing so. I realise though that i did not share your original issue so if this is irrelevant please ignore.

from resolvers.

brianbattenfeld avatar brianbattenfeld commented on June 18, 2024 1

@yamatsum something like the following, though you might need to do a little shuffling around since you're wrapping this all and using the generic.

useForm<InferType<typeof schema>>()

from resolvers.

Supcar27 avatar Supcar27 commented on June 18, 2024 1

also facing this issue, has a fix been found?

from resolvers.

jorisre avatar jorisre commented on June 18, 2024

Can you provide a Codesandbox with the issue? thank you

from resolvers.

Hujianboo avatar Hujianboo commented on June 18, 2024

I have the same problem in version 3.0 plus. You can change the
export interface CreateFormOptions<T> { rules: Record<keyof T, yup.AnySchema>; defaultValues?: DefaultValues<T>; validateMode?: Mode; }
to
export interface CreateFormOptions<T> { rules: Record<keyof T, yup.AnySchema>; defaultValues: DefaultValues<T> | undefined; validateMode: Mode | undefined; } It worked for me

from resolvers.

yamatsum avatar yamatsum commented on June 18, 2024

@jorisre @Hujianboo
thank you for your reply
The method you suggested didn't fix it.

https://codesandbox.io/p/devbox/snowy-browser-xvhgk5?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clq7chv6y000a3b6ilzukmo1k%2522%252C%2522sizes%2522%253A%255B70%252C30%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clq7chv6x00023b6iebsjsvcy%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clq7chv6x00073b6ice12ck93%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clq7chv6x00093b6iz0zrivb6%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clq7chv6x00023b6iebsjsvcy%2522%253A%257B%2522id%2522%253A%2522clq7chv6x00023b6iebsjsvcy%2522%252C%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clq7ciiep00563b6igqb0rvxy%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252Fsrc%252Fcomponents%252FForm.tsx%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%255D%252C%2522activeTabId%2522%253A%2522clq7ciiep00563b6igqb0rvxy%2522%257D%252C%2522clq7chv6x00093b6iz0zrivb6%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clq7chv6x00083b6imqf2d6xb%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_PORT%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522port%2522%253A3000%252C%2522path%2522%253A%2522%252F%2522%257D%255D%252C%2522id%2522%253A%2522clq7chv6x00093b6iz0zrivb6%2522%252C%2522activeTabId%2522%253A%2522clq7chv6x00083b6imqf2d6xb%2522%257D%252C%2522clq7chv6x00073b6ice12ck93%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clq7chv6x00033b6igo5r621i%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522dev%2522%257D%252C%257B%2522id%2522%253A%2522clq7chv6x00043b6i6oz0lyrd%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522start%2522%257D%252C%257B%2522id%2522%253A%2522clq7chv6x00053b6imsdq6wxa%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522install%2522%257D%252C%257B%2522id%2522%253A%2522clq7chv6x00063b6i8790tguq%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TERMINAL%2522%252C%2522shellId%2522%253A%2522clq7bgw85014pehgebt5w2y9w%2522%257D%255D%252C%2522id%2522%253A%2522clq7chv6x00073b6ice12ck93%2522%252C%2522activeTabId%2522%253A%2522clq7chv6x00033b6igo5r621i%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

from resolvers.

greeeg avatar greeeg commented on June 18, 2024

StackOverflow issue mentioning the same generic issue since upgrading: https://stackoverflow.com/questions/77593266/the-react-hook-forms-yup-resolver-is-upgraded-and-causes-a-type-error

from resolvers.

greeeg avatar greeeg commented on June 18, 2024

@tjelvar-chromaway We would need your yarn.lock or package-lock.json file to see what exact versions you're using to explain why it works on your side.

On my side, in the CI with pinned versions, it does not work consistently

from resolvers.

tjelvar-chromaway avatar tjelvar-chromaway commented on June 18, 2024

@greeeg Got the same versions in the lock file

  '@hookform/resolvers':
    specifier: ^3.3.3
    version: 3.3.3([email protected])
    
   react-hook-form:
    specifier: ^7.49.2
    version: 7.49.2([email protected])
    
   yup:
    specifier: 1.3.3
    version: 1.3.3

(deleted both node_modules and my lock file and re-installed everything)

from resolvers.

yamatsum avatar yamatsum commented on June 18, 2024

I deleted node_modules and also deleted the lock file, but the error remained.

from resolvers.

Zerebokep avatar Zerebokep commented on June 18, 2024

I have the same problem, as soon as I use Fieldvalues as parameter, typescript complains that the types of the schema doesn't match. This started at > 3.1.0, I'm also using yup.

from resolvers.

brianbattenfeld avatar brianbattenfeld commented on June 18, 2024

Similar issue here. Brand new to this so it didn't become broken after an upgrade but after downgrading to the versions mentioned by @yamatsum, this works as expected according to the docs.

I was able to work around it for the time being by using yup.InferType, but this likely won't work for everyone's use cases and I'm not entirely sure yet how trustworthy these results will be.

from resolvers.

yamatsum avatar yamatsum commented on June 18, 2024

@brianbattenfeld
In this case, how can I use yup.InferType to solve the problem?
#648 (comment)

from resolvers.

lucamartins avatar lucamartins commented on June 18, 2024

Same problem here.

from resolvers.

vincent-vdl avatar vincent-vdl commented on June 18, 2024

Also facing this issue.

from resolvers.

mikecousins avatar mikecousins commented on June 18, 2024

Same here.

from resolvers.

japusoy avatar japusoy commented on June 18, 2024

Was able to fix it.

from

const validationSchema = Yup.object().shape({
  email: Yup.string().email().required(errors.field),
  password: Yup.string().required(errors.field).min(5),
});

to

const validationSchema = Yup.object({
  email: Yup.string().email().required(errors.field),
  password: Yup.string().required(errors.field).min(5),
});

jquense/yup#1222 (comment)

from resolvers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.