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

feat infer form type from zod schema and fix test #447

Conversation

kagurazaka-0
Copy link

@kagurazaka-0 kagurazaka-0 commented Aug 28, 2022

  • feat infer FormType from zod schema without using type assertion
const HogeSchema = z.object({
  name: z.string(),
  age: z.number(),
});

const _ = useForm({ resolver: zodResolver(HogeSchema) });
// _ is UseFormReturn<{ name: string; age: number }>

_.watch("age") // work! it is number 
_.watch("name") // work! it is string
  • fix type error in test

I referred to #417, thanks @maddijoyce !

@kagurazaka-0 kagurazaka-0 marked this pull request as ready for review August 28, 2022 17:28
@kagurazaka-0
Copy link
Author

@jorisre why not reviewed and merged?
doing something wrong?

@jorisre
Copy link
Member

jorisre commented Oct 5, 2022

Hi sorry for the delay. Here is a related issue #429
That explain why we don't infer from resolver. consider using useForm<z.infer<typeof HogeSchema>>({ resolver: zodResolver(HogeSchema) })

@kagurazaka-0
Copy link
Author

ok. sorry i missed it😢

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

Successfully merging this pull request may close these issues.

2 participants