TypeScript definitions for `styled` miss `target` prop for material ui Button
See original GitHub issueCurrent behavior:
When using styled
(either from @emotion/styled
or via @mui/material
) to style <Button>
from @mui/material
, TypeScript complains about target
prop. It does not complain about the prop on bare <Button>
.
The prop works as expected though, the error is only with TypeScript.
To reproduce:
Reproduction provided by Material UI team at https://github.com/mui/material-ui/issues/31314#issuecomment-1067776719
https://codesandbox.io/s/hardcore-danilo-0e086c?file=/src/App.tsx
- Wrap
<Button>
withstyled
- Use new component with
target
prop
TS reports this error:
Type '{ children: string; variant: "outlined"; href: string; target: string; }' is not assignable to type 'IntrinsicAttributes & { children?: ReactNode; classes?: Partial<ButtonClasses> | undefined; color?: "inherit" | "primary" | ... 5 more ... | undefined; ... 9 more ...; variant?: "text" | ... 2 more ... | undefined; } & ... 4 more ... & { ...; }'.
Property 'target' does not exist on type 'IntrinsicAttributes & { children?: ReactNode; classes?: Partial<ButtonClasses> | undefined; color?: "inherit" | "primary" | ... 5 more ... | undefined; ... 9 more ...; variant?: "text" | ... 2 more ... | undefined; } & ... 4 more ... & { ...; }'
This can be workarounded with styled(Button)(....) as unknown as typeof Button
.
Expected behavior:
Prop works w/o TypeScript errors.
Environment information:
react
version: 17.0.2@emotion/react
version: 11.8.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
TS types for `styled` and `Button` are not compatible: target ...
I am trying to customize Button using styled from @mui/material . Your environment. See codesandbox.
Read more >'styled()' function drops 'component' prop support
ButtonBase is working as expected, but suddenly there is an error from Typescript, telling that there is no 'component' prop on MyButton ....
Read more >TypeScript - Material UI - MUI
Many components concerned with user input offer a value prop or event handlers which include the current value . In most situations that...
Read more >How to use styled components with Material UI in a React app
It works as follow: import styled from "styled-components"; import Button from "@material-ui/core/Button"; export default styled(Button)` color ...
Read more >react-dropzone
Simple React hook to create a HTML5-compliant drag'n'drop zone for files. Documentation and examples at https://react-dropzone.js.org.
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
Thanks @mnajdova. Seems like it is not practical for us to work around this limitation in TypeScript so I am closing the issue.
See https://github.com/mui/material-ui/issues/31314#issuecomment-1076457447, in my opinion this should be closed.