question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Typescript] Button do not accept custom component

See original GitHub issue
  • [ x] The issue is present in the latest release.
  • [ x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

              <Button component={Link} variant="outlined" size="small">
                Sign in
              </Button>
image image image

Expected Behavior 🤔

It should be able to pass component image

Steps to Reproduce 🕹

Steps:

Context 🔦

Your Environment 🌎

//tsconfig.json
{
  "compilerOptions": {
    "allowJs": true,
    "baseUrl": ".",
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "jsx": "preserve",
    "lib": ["dom", "dom.iterable", "esnext"],
    "module": "esnext",
    "skipLibCheck": true,
    "moduleResolution": "node",
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "paths": {
      "@/*": ["./*"]
    },
    "removeComments": true,
    "resolveJsonModule": true,
    "sourceMap": true,
    "strict": true,
    "strictPropertyInitialization": false,
    "target": "esnext",
    "isolatedModules": true
  }
}
Tech Version
Material-UI v4.3.1
React 16.8.6
Browser
TypeScript 3.5.3
etc.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
khryshyncommented, Aug 5, 2019

The solution is not working if you’re using the styled-components

0reactions
vishalrajolecommented, Jul 22, 2021

I confirm same issue with Button and styled components in version

"@emotion/react": "11.4.0",
"@emotion/styled": "11.3.0",
"@material-ui/core": "5.0.0-alpha.37",
"@material-ui/icons": "5.0.0-alpha.37",
"styled-components": "5.2.3",
"typescript": "4.2.4"

I am consuming styled button as below

<S.ProfileButton
      aria-describedby={id}
      component="span"                // <=== _typescript errors out here for component prop_
      onClick={handleClick}
      endIcon={<ExpandMoreProfileIcon />}>
      .......other code
</S.ProfileButton>

Button wrapped as Styled component

import { Button } from '@material-ui/core';
........ other code
export const ProfileButton = styled(Button)`
    width: 100%;
    border-radius: 0;
    background-color: ${Colors.black};
    height: 72px;
}`;

Error


No overload matches this call.
  Overload 1 of 2, '(props: Omit<Omit<{ children?: ReactNode; classes?: Partial<ButtonClasses> | undefined; color?: "inherit" | "error" | "secondary" | "primary" | "success" | "info" | "warning" | undefined; ... 9 more ...; variant?: "text" | ... 2 more ... | undefined; } & Omit<...> & CommonProps & Omit<...>, never> & Partial<...>, "theme"> & { ...; } & { ...; }): ReactElement<...>', gave the following error.
    Type '{ children: Element; "aria-describedby": string | undefined; component: string; onClick: (event: MouseEvent<HTMLElement, MouseEvent>) => void; endIcon: Element; }' is not assignable to type 'IntrinsicAttributes & Omit<Omit<{ children?: ReactNode; classes?: Partial<ButtonClasses> | undefined; color?: "inherit" | ... 6 more ... | undefined; ... 9 more ...; variant?: "text" | ... 2 more ... | undefined; } & Omit<...> & CommonProps & Omit<...>, never> & Partial<...>, "theme"> & { ...; } & { ...; }'.
      Property 'component' does not exist on type 'IntrinsicAttributes & Omit<Omit<{ children?: ReactNode; classes?: Partial<ButtonClasses> | undefined; color?: "inherit" | ... 6 more ... | undefined; ... 9 more ...; variant?: "text" | ... 2 more ... | undefined; } & Omit<...> & CommonProps & Omit<...>, never> & Partial<...>, "theme"> & { ...; } & { ...; }'.
  Overload 2 of 2, '(props: StyledComponentPropsWithAs<ExtendButtonBase<ButtonTypeMap<{}, "button">>, any, {}, never, ExtendButtonBase<ButtonTypeMap<{}, "button">>, ExtendButtonBase<...>>): ReactElement<...>', gave the following error.
    Type '{ children: Element; "aria-describedby": string | undefined; component: string; onClick: (event: MouseEvent<HTMLElement, MouseEvent>) => void; endIcon: Element; }' is not assignable to type 'IntrinsicAttributes & Omit<Omit<{ children?: ReactNode; classes?: Partial<ButtonClasses> | undefined; color?: "inherit" | ... 6 more ... | undefined; ... 9 more ...; variant?: "text" | ... 2 more ... | undefined; } & Omit<...> & CommonProps & Omit<...>, never> & Partial<...>, "theme"> & { ...; } & { ...; }'.
      Property 'component' does not exist on type 'IntrinsicAttributes & Omit<Omit<{ children?: ReactNode; classes?: Partial<ButtonClasses> | undefined; color?: "inherit" | ... 6 more ... | undefined; ... 9 more ...; variant?: "text" | ... 2 more ... | undefined; } & Omit<...> & CommonProps & Omit<...>, never> & Partial<...>, "theme"> & { ...; } & { ...; }'.ts(2769)

Here is code sandbox replicating same issue. https://codesandbox.io/s/mui-styled-button-vliel?file=/src/App.tsx @oliviertassinari appreciate your help here again as this is blocking 👏

Screenshot 2021-07-22 at 9 50 33 AM

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Typescript] Button do not accept custom component #16887
[ x] The issue is present in the latest release. [ x] I have searched the issues of this repository and believe that...
Read more >
How to Build a Custom Button Component in React TypeScript
Follow best programming practices by learning how to write a reusable custom button component for a basic TypeScript React project.
Read more >
How to prevent clicks to custom button component in Angular 4
You can use @HostBinding('class') and :host -selectors to disable clicks via pointer-events: none based on your shouldBeDisabled property:
Read more >
Making your components extensible with TypeScript
The <Button /> we have so far isn't really useful, is it? So, let's add some custom properties. Adding custom properties. For the...
Read more >
Useful Patterns by Use Case - React TypeScript Cheatsheets
ComponentPropsWithoutRef<'button'>. // usage function App() { // Type '"foo"' is not assignable to type '"button" | "submit" | "reset" | undefined'.(2322)
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found