live demo link: https://codesandbox.io/s/style-components-spread-error-cg189?file=/src/MySlider.tsx
I try to wrap input element into react component to apply custom styles and markup. I would like to use it just like any other input element, by using value, onChange etc. But typescript does not like spreading props on styled input. I could cast props to any, but I would like to know why this is a problem in the first place. Thanks!
const MyRange = styled.input.attrs({ type: 'range' as string })`
/* styles */
`;
export const MySlider: FC<HTMLProps<HTMLInputElement>> = (props) => {
return (
<>
<MyRange {...props} />
// ^^^^^^^ Types of property 'ref' are incompatible.
<span>{props.value}</span>
</>
);
};