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

conform's automatic type coercion doesn't work with z.discriminatedUnion #339

Closed
jmaldon1 opened this issue Nov 20, 2023 · 2 comments
Closed

Comments

@jmaldon1
Copy link

jmaldon1 commented Nov 20, 2023

Describe the bug and the expected behavior

z.discriminatedUnion should be doing automatic type coercion like a normal schema that just uses a z.object but it doesn't seem to do that. Everything works fine if i add .coerce to the failing fields in my schema.

Conform version

0.9.0

Steps to Reproduce the Bug or Issue

const schema = z.discriminatedUnion("type", [
  z.object({
    type: z.literal("copy"),
    id: z.number(),
  }),
]);

Fails validation with the following error:

{
  intent: 'submit',
  payload: { type: 'copy', id: '43' },
  error: { id: [ 'Expected number, received string' ] }
}

Form:

<Form {...formProps} method="POST">
  <input
    type="hidden"
    name="type"
    value="copy"
  />
  <input
    type="hidden"
    name="id"
    value={id}
  />
  <Button type="submit">Copy</Button>
</Form>

What browsers are you seeing the problem on?

No response

Screenshots or Videos

No response

Additional context

No response

@edmundhung
Copy link
Owner

This should be resolved with #340. Thanks for reporting!

@edmundhung
Copy link
Owner

This should be fixed in v1.0.0.

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 a pull request may close this issue.

2 participants