-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
Breaking change to Validate
in 6.5.1
#265
Comments
It seems like the issue is specific to the I don't have any pressing need to upgrade the version so my solution for now is just to lock the version to |
could you provide a repo / codesandbox which higlights the issue that would be helpful |
@rynoV have you tested it with v6.8.0 or the latest version v7.0.0? |
I see the issue on both of these versions Here's a sandbox: https://codesandbox.io/p/sandbox/react-hook-form-mui-zh4mxg It looks like somewhere past I couldn't find a way to make type inference work to find the most specific |
@rynoV you would never need to provide it in the way you did in, here is an updated version: you can also have a look at https://github.com/dohomi/react-hook-form-mui/blob/master/apps/storybook/stories/FormContainer.stories.tsx#L145 which is meant to have strict typings example. Basically if you provide |
I add a typesafe example to the landing page of Github https://github.com/dohomi/react-hook-form-mui?tab=readme-ov-file#typesafe-form-setup |
@dohomi Thanks for the example in the docs. I couldn't access the sandbox you sent, but I tried to update my sandbox based on the example in the docs and the type error is still present until I specify the second generic: https://codesandbox.io/p/sandbox/react-hook-form-mui-zh4mxg?file=%2Fsrc%2FApp.tsx%3A10%2C32 Re the other Please let me know if I'm missing anything |
you should not pass any types because https://codesandbox.io/p/devbox/h3spsq?file=%2Fsrc%2FApp.tsx import { FieldPath, useForm } from "react-hook-form";
import { AutocompleteElement } from "react-hook-form-mui";
import "./styles.css";
interface FormValues {
field: string;
otherField: number;
}
export default function App() {
const { control, handleSubmit } = useForm<FormValues>({
defaultValues: {
field: "",
otherField: 0,
},
});
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<AutocompleteElement
control={control}
name={"field"}
options={[]}
rules={{
validate: {
parse(value) {
console.log(value);
return true;
},
},
}}
/>
</div>
);
} |
Ah okay I see now, don't specify any generics and pass a control. I wasn't passing control before because I was relying on It would be nice if I didn't need to change the code purely to affect things at the type level, but it seems like this would require partial type inference to stop typescript from using the default value for the Appreciate the help |
Duplicates
Latest version
Current behavior 😯
Thanks for making this!
I'm mostly just filing this for documentation: there was a breaking change to the types in version
6.5.1
, in this commit 75d70f4. When using therules
orvalidation
props on some elements there might be a new type error like:Expected behavior 🤔
No response
Steps to reproduce 🕹
Steps:
The text was updated successfully, but these errors were encountered: