[styled(Link)] TypeScript error: Link does not accept `component` attribute
See original GitHub issue- This is not a v0.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior 🤔
I should be able to specify which component my styled <Link>
should use to display, e.g.:
import { Link as RouterLink } from "react-router-dom"
import { Link } from "@material-ui/core"
import { styled } from "@material-ui/styles"
const StyledLink = styled(Link)({
color: "red",
})
export default () =>
<StyledLink component={RouterLink} to="/password">Forgot your password?</StyledLink>
Current Behavior 😯
TypeScript error in Login.tsx(123,16):
Type '{ children: string; component: typeof Link; }' is not assignable to type 'IntrinsicAttributes & Pick<DefaultComponentProps<{ props: AnchorHTMLAttributes<HTMLAnchorElement> & Pick<TypographyProps, "style" | "title" | "color" | "display" | "hidden" | "ref" | "children" | ... 255 more ... | "variantMapping"> & { ...; }; defaultComponent: "a"; classKey: LinkClassKey; }>, "style" | ... 270 mor...'.
Property 'component' does not exist on type 'IntrinsicAttributes & Pick<DefaultComponentProps<{ props: AnchorHTMLAttributes<HTMLAnchorElement> & Pick<TypographyProps, "style" | "title" | "color" | "display" | "hidden" | "ref" | "children" | ... 255 more ... | "variantMapping"> & { ...; }; defaultComponent: "a"; classKey: LinkClassKey; }>, "style" | ... 270 mor...'. TS2322
Steps to Reproduce 🕹
https://codesandbox.io/s/loving-cannon-ed5e8
Context 🔦
I want to style to my link, but maybe there are other ways 😃
Your Environment 🌎
Tech | Version |
---|---|
@material-ui/core | 4.0.0-beta.2 |
@material-ui/styles | 4.0.0-beta.2 |
react-router-dom | @5.0.0 |
React | 16.8.6 |
Browser | Chrome 74 macOS |
TypeScript | 3.4.5 |
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
[styled(Link)] TypeScript error: Link does not accept ... - GitHub
This is a TypeScript limitation regarding argument inference and overloaded function signatures. const StyledLink = styled(Link)({ ...
Read more >React styled-component with Typescript, types error
I have a isActive prop on the Link Styled component. The console complains about this because it dose not recognize isActive as a...
Read more >TypeScript - Emotion
When using our JSX factory, TypeScript only allows the css prop on components that accept a className prop. This is because @emotion/react resolves...
Read more >Advanced Usage - styled-components
This component provides a theme to all React components underneath itself via the context API. In the render tree all styled-components will have...
Read more >Useful Patterns by Use Case - React TypeScript Cheatsheets
Type '"foo"' is not assignable to type '"button" | "submit" | "reset" | undefined'.(2322) // return <Button type="foo"> sldkj </Button> // no error...
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 Free
Top 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
This is a TypeScript limitation regarding argument inference and overloaded function signatures.
should fit too but removes all types for props from
styled
.Shouldn’t this be
as typeof Link
? I.e: