ui icon indicating copy to clipboard operation
ui copied to clipboard

`Checkbox` component `checked` property showing a TypeError for passing a boolean value

Open PlagueFPS opened this issue 1 year ago • 6 comments

image react-hook-form version: 7.47.0 zod validation for field: z.boolean()

I followed the guide on implementing the checkbox directly from the component docs: https://ui.shadcn.com/docs/components/checkbox#form

I also noticed that the type for the checked property is CheckedState and when I went to look at the type it has a type definition of: boolean | "indeterminate"

I am passing a boolean value as it expects, but, the Checkbox component itself seems to have conflicting types with this since it tells me I can only pass in a string | number | string[] | readonly string[] | undefined

There are many ways I can get around this, but, it should not be showing a TypeError here.

PlagueFPS avatar Oct 19 '23 08:10 PlagueFPS

Additional note: the property it's showing a TypeError for is the value property which I am not even using. This isn't that surprising though as I assume it maps the field.value property to the actual value property causing the error via the {...field}.

I am not sure if this intended behavior (I assume not since it's not in the documentation), but, for now I'm going with the easiest solution which is setting a value property along with the checked value and just coercing the boolean into a string.

Documentation and/or Types may need to be updated I'm not sure, but, please let me know if this is expected or not.

PlagueFPS avatar Oct 19 '23 08:10 PlagueFPS

Maybe you need to provide an online demo that reproduces the bug

headironc avatar Oct 19 '23 09:10 headironc

@headironc I don't think that would help as the TypeError doesn't prevent the functionality at all, it just fails to build when pushed to a hosting service when checking type validity.

PlagueFPS avatar Oct 19 '23 09:10 PlagueFPS

Screenshot 2023-10-19 at 18 07 35

No error found with my demo

headironc avatar Oct 19 '23 10:10 headironc

Maybe you need this api reference

headironc avatar Oct 19 '23 12:10 headironc

image react-hook-form version: 7.47.0 zod validation for field: z.boolean()

I followed the guide on implementing the checkbox directly from the component docs: https://ui.shadcn.com/docs/components/checkbox#form

I also noticed that the type for the checked property is CheckedState and when I went to look at the type it has a type definition of: boolean | "indeterminate"

I am passing a boolean value as it expects, but, the Checkbox component itself seems to have conflicting types with this since it tells me I can only pass in a string | number | string[] | readonly string[] | undefined

There are many ways I can get around this, but, it should not be showing a TypeError here.

Don't spread props {...field}, instead just use the props that you require directly

eovandodev avatar Jan 19 '24 16:01 eovandodev

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Feb 14 '24 23:02 shadcn