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.

[prop component] ButtonBaseProps not accepting a component property

See original GitHub issue

Expected Behavior 🤔

component property should be accepted

Current Behavior 😯

component property is not accepted

Steps to Reproduce 🕹

const props: ButtonProps<'span'> = {
  component: 'span',
  ^^^^^^^^^^^^^^^^^ 'component' does not exist in type ...
  onClick(event: React.MouseEvent<HTMLSpanElement>) {},
};

Context 🔦

Need for integration with a third-party routing library

Your Environment 🌎

Tech Version
Material-UI v4.0.0
TypeScript v4.1.0

Edit @eps1lon: Heavily editorialized the original issue which was inaccurate and misleading.

Most of the issue has been solved, see https://next.material-ui.com/guides/typescript/#usage-of-component-prop

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:45
  • Comments:75 (51 by maintainers)

github_iconTop GitHub Comments

30reactions
bengrycommented, May 25, 2019

To add to this, the following doesn’t compile in TypeScript in MUIv4, but should:

// MyButton.ts
import { Button } from '@material-ui/core'
import { ButtonProps } from '@material-ui/core/Button'
import React from 'react'

export const MyButton = React.forwardRef<HTMLButtonElement, ButtonProps>((btnProps, ref) => (
  <Button
    ref={ref}
    variant="contained"
    color="primary"
    {...btnProps}
  />
))

// MyPage.ts

function MyPage() {
  return (
    <MyButton component={Link}> // <-- error on this
      Click me
    </MyButton>
  )
}

error message is:

Type ‘{ children: string; component: FunctionComponent<{}>; }’ is not assignable to type ‘IntrinsicAttributes & Pick<{ action?: ((actions: ButtonBaseActions) => void) | undefined; buttonRef?: ((instance: unknown) => void) | RefObject<unknown> | null | undefined; centerRipple?: boolean | undefined; … 6 more …; TouchRippleProps?: Partial<…> | undefined; } & { …; } & CommonProps<…> & Pick<…>, "c…’. Property ‘component’ does not exist on type ‘IntrinsicAttributes & Pick<{ action?: ((actions: ButtonBaseActions) => void) | undefined; buttonRef?: ((instance: unknown) => void) | RefObject<unknown> | null | undefined; centerRipple?: boolean | undefined; … 6 more …; TouchRippleProps?: Partial<…> | undefined; } & { …; } & CommonProps<…> & Pick<…>, "c…’.

I’m using TypeScript 3.3.3, but also checked 3.4.5, and getting the same error

15reactions
alexeychikkcommented, Dec 9, 2020

Is this about to be fixed or is it even considered a bug? I just copy-pasted the code from the docs for my link component with minor changes and the TS error shows up:

Property ‘component’ does not exist on type 'IntrinsicAttributes…

import Button, { ButtonProps } from "@material-ui/core/Button";
import { withStyles, WithStyles } from "@material-ui/core/styles";
import { GatsbyLinkProps, Link } from "gatsby";
import * as React from "react";

import { styles } from "./ButtonLink.styles";

export type ButtonLinkProps = WithStyles<typeof styles> &
  ButtonProps &
  GatsbyLinkProps<{}> & {
    partiallyActive?: boolean;
    replace?: boolean;
    to: string;
  };

const LinkComponent = React.forwardRef<HTMLAnchorElement, GatsbyLinkProps<{}>>(
  ({ ref, innerRef, ...props }, linkRef) => (
    <Link innerRef={linkRef as Function} {...props} />
  ),
);

class ButtonLink extends React.PureComponent<ButtonLinkProps> {
  public render() {
    const { classes, innerRef, ...props } = this.props;
    return (
      <Button
   {/* ^^^^^^ Property 'component' does not exist on type 'IntrinsicAttributes... */}
        component={LinkComponent}
        activeClassName={classes.active}
        {...props}>
        {this.props.children}
      </Button>
    );
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to extend props for Material-UI components using ...
I get the following errors: TS2323: Cannot redeclare exported variable 'Button'. TS2484: Export declaration conflicts with exported declaration ...
Read more >
Section 2: Excluding Props - React TypeScript Cheatsheets
The problem we want to solve is having the HOC-wrapped-component exposing a type that reflects the reduced surface area of props - without...
Read more >
material-ui/core/CHANGELOG.md - UNPKG
96, - [docs] Add Material-UI Builder to in-house ads (#23342) @mbrookes ... 795, - [Card] Fix TypeScript not recognizing "component" prop (#20179) @rart....
Read more >
ButtonBase API - Material UI - MUI
Name Type Default action ref centerRipple bool false children node
Read more >
typescript react component type as prop - Industry Today
Property 'value' does not exist on type 'EventTarget'. ... I initially had an interface of props like so for the receiving component: type...
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