Custom radio buttons example does not work in TypeScript
See original GitHub issue🐛 Bug report
I’m trying to use the Chakra UI custom radio buttons example for my TypeScript React project.
💥 Steps to reproduce
Copy the example component into your project, adding the necessary props type:
function RadioCard(props: PropsWithChildren<UseRadioProps>) {
const { getInputProps, getCheckboxProps } = useRadio(props);
const input = getInputProps();
const checkbox = getCheckboxProps();
return (
<Box as="label">
<input {...input} />
<Box
{...checkbox}
cursor="pointer"
borderWidth="1px"
borderRadius="md"
boxShadow="md"
_checked={{
bg: "teal.600",
color: "white",
borderColor: "teal.600",
}}
_focus={{
boxShadow: "outline",
}}
px={5}
py={3}
>
{props.children}
</Box>
</Box>
);
}
Experience the following compilation error:
error TS2322: Type '{ children: ReactNode; cursor: "pointer"; borderWidth: "1px"; borderRadius: "md"; boxShadow: "md"; _checked:
{ bg: string; color: string; borderColor: string; }; _focus: { boxShadow: string; }; ... 256 more ...; css?: CSSProp<...> | undefined; }' is not assignable to type 'ChakraProps'.
Types of property 'css' are incompatible.
Type 'CSSProp<any> | undefined' is not assignable to type 'Interpolation<{}>'.
Type 'FlattenInterpolation<ThemeProps<any>>' is not assignable to type 'Interpolation<{}>'.
Type 'readonly Interpolation<ThemeProps<any>>[]' is missing the following properties from type 'ArrayInterpolation<{}>': pop, push, reverse, shift, and 6 more.
🧐 Expected behavior
The example should work in a TypeScript project.
🌍 System information
Software | Version(s) |
---|---|
Chakra UI | 1.6.1 |
Browser | N/A |
Operating System | Windows |
📝 Additional information
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:5 (1 by maintainers)
Top Results From Across the Web
reactjs - Customized Radio Button Input does not work as ...
I created a customized radio button with help of styled-components and react-typescript The working code is here on codesandbox.
Read more >How to Create a Reusable Custom Radio Button in React with ...
1. Ensure good usability · 2. Readability is crucial · 3. Radio buttons are for selection only · 4. Always define a default...
Read more >Typescript error when using custom radio group with ... - GitHub
I came across this discussion which has a working solution on codesandbox but it also shows the same error. I cannot decipher this,...
Read more >Don't Fear Custom Radio Buttons - DEV Community
It is a set of checkable buttons, known as radio buttons, where no more than one of the buttons can be checked at...
Read more >How to get value of selected radio button using JavaScript?
To get the value of the selected radio button, a user-defined function can be created that gets all the radio buttons with the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @rossng,
This error is very common when you have multiple instances of emotion in
node_modules
. Storybook is usually the suspect here since they use the older versions of emotion which pollutes the TS namespace with thatcss
type definition.I’d recommend creating a
.yarnclean
file and include@emotion/core/types
to fix that type definition. You can so try @CaitlinSweeney’s solution (thank you, Caitlin!)If the issue persists, please send a reproduction link.
I’ll leave this here if it helps someone else, not sure what your children look like-
I think I had a similar error @mjgwood. Did you try using the
UseRadioProps
?Also, check to make sure your
value
is a string, ie:{...getRadioProps({ value: someValue.toString() })}