[Button] Type conflict in Button component's href
prop when using component
prop
#42788
Labels
component: button
This is the name of the generic UI component, not the React module!
enhancement
This is not a bug, nor a new feature
typescript
Steps to reproduce
Link to live example: https://github.com/odan-sandbox/repro-mui-button-component-type-conflict/blob/main/src/repro.tsx
Steps:
src/repro.tsx
in VSCode.Current behavior
When using the
component
prop with the Button component, thehref
prop type does not get overridden as expected. Thecomponent
prop is assigned a component that acceptshref
with the typestring | UrlObject
. However, thehref
prop in the Button component remains with the typestring
, leading to a type conflict.Expected behavior
When using the
component
prop with the Button component, the type of thehref
prop should be overridden to match the type of thehref
prop in the assigned component. Specifically, thehref
prop in the Button component should acceptstring | UrlObject
instead of juststring
.Context
In our project, we are using the MUI Button component in combination with Next.js's Link component via the
component
prop. The Link component has anhref
prop that accepts astring | UrlObject
type. This issue arises when we use theUrlObject
type, which is utilized by pathpida, a tool for Next.js that automatically generates URL-related code based on file-based routing. pathpida represents URLs asUrlObject
rather than strings.The type conflict between the Link component's
href
prop and the MUI Button component'shref
prop (which only accepts strings) prevents us from fully leveraging the benefits of pathpida.Your environment
$ npx @mui/envinfo
tsconfig
Search keywords: Button href type OverrideProps
The text was updated successfully, but these errors were encountered: