gravity-ui / uikit

https://gravity-ui.com
MIT License
522 stars 85 forks source link

Button. Non-generic types doesn't allow to use `react-router` Link as a component #1128

Open zzzorgo opened 7 months ago

zzzorgo commented 7 months ago

What I am trying to do is to use button as an anchor element. Since there is support for the component prop to substitute default button element with a custom one and extraProps prop to provide any props to that component, I expect those props to be typed as variable type depending on the component provided, but that is not the case.

Actual typing is non-generic

extraProps?: React.ButtonHTMLAttributes<HTMLButtonElement> | React.AnchorHTMLAttributes<HTMLAnchorElement>;

react-router uses prop named to instead of href, so I get a typescript error.

Example

import {Link} from 'react-router-dom';

/* ... */

<Button
    component={Link}
    extraProps={{
        to: "some-url",
    }}
>
    Some link-button
</Button>
amje commented 7 months ago

@zzzorgo I'll try to improve typing here