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
Default value breaks types #478
Comments
From what I understand, the A workaround I found is to fallback all string values to |
It looks like Typescript is trying to infer the types from both A temporary solution is to set the type manually to stop typescript from inferring it. const [form, fields] = useForm<z.input<typeof schema>>({
// ...
}); |
Yeah I've already tried to apply NoInfer directly in the conform source code but to no avail 😂 |
Typescript seems to infer the type correctly if you spread over the const [form, fields] = useForm({
lastResult,
onValidate({ formData }) {
return parseWithZod(formData, { schema: LinkPageFormSchema });
},
defaultValue: {
...defaultValues
},
}); |
@edmundhung, I've done my best to create an isolated reproduction of the problems here: TypeScript Playground As you can see, in most places schema type inference is working exactly opposite of what's expected. For example, if you hover over the last Thankfully, passing explicit type arguments always works as expected, which I've also demonstrated in the reproduction. So for now, this is what we'll do in our codebase. What's truly maddening is that on line 18, if you switch |
Describe the bug and the expected behavior
When using for example zod discriminated union for form schema, providing default value breaks the types completely.
Conform version
v1.0.2
Steps to Reproduce the Bug or Issue
https://stackblitz.com/edit/github-qiy4lh-vn8142?file=app%2Froutes%2Ftype-inference.tsx
What browsers are you seeing the problem on?
No response
Screenshots or Videos
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: