mui / material-ui

Material UI: Ready-to-use foundational React components, free forever. It includes Material UI, which implements Google's Material Design.
https://mui.com/material-ui/
MIT License
92.43k stars 31.84k forks source link

[Chip] `disableRipple` causes TypeScript error "No overload matches this call." #23041

Open jfeigel opened 3 years ago

jfeigel commented 3 years ago

Current Behavior 😯

disableRipple works as expected, however a TypeScript error is thrown.

TypeScript error ``` No overload matches this call. Overload 1 of 2, '(props: { component: ElementType; } & { avatar?: ReactElement ReactElement Component)> | null) | (new (props: any) => Component<...>)> | undefined; ... 9 more ...; variant?: "default" | ... 1 more ... | undefined; } & CommonProps<...> & Pick<...>): Element', gave the following error. Property 'component' is missing in type '{ label: string; onClick: () => void; disableRipple: true; }' but required in type '{ component: ElementType; }'. Overload 2 of 2, '(props: DefaultComponentProps>): Element', gave the following error. Type '{ label: string; onClick: () => void; disableRipple: true; }' is not assignable to type 'IntrinsicAttributes & { avatar?: ReactElement ReactElement Component)> | null) | (new (props: any) => Component<...>)> | undefined; ... 9 more ...; variant?: "default" | ... 1 more ... | undefined; } & CommonProps<...> & Pick<...>'. Property 'disableRipple' does not exist on type 'IntrinsicAttributes & { avatar?: ReactElement ReactElement Component)> | null) | (new (props: any) => Component<...>)> | undefined; ... 9 more ...; variant?: "default" | ... 1 more ... | undefined; } & CommonProps<...> & Pick<...>'.ts(2769) OverridableComponent.d.ts(17, 7): 'component' is declared here. ```

Expected Behavior 🤔

No TypeScript error should be thrown.

Steps to Reproduce 🕹

Steps:

  1. Use TypeScript and Material-UI
  2. Add the disableRipple prop to a Chip.

https://codesandbox.io/s/divine-star-nimfs?file=/src/Demo.tsx

Your Environment 🌎

Tech Version
Material-UI v4.11.0 and v5.0.0-alpha12
React v16.13.1
TypeScript 3.9.7

tsconfig.json

{
    "include": [
        "./src/**/*"
    ],
    "compilerOptions": {
        "strict": true,
        "esModuleInterop": true,
        "lib": [
            "dom",
            "es2015"
        ],
        "jsx": "react"
    }
}
enricopolanski commented 3 years ago

disableRipple isn't part of the Chip API afaik:

https://material-ui.com/api/chip/

oliviertassinari commented 3 years ago

@enricopolanski Is right, the prop is only available in some use cases. You can dodge the issue with:

import React from "react";
import { Chip } from "@material-ui/core";

export default function Demo() {
  const more = { disableRipple: true };
  return <Chip label="Material Chip" onClick={() => {}} {...more} />;
}

https://codesandbox.io/s/naughty-visvesvaraya-i9c59?file=/src/Demo.tsx

tomhalley commented 1 year ago

@enricopolanski @oliviertassinari If it isn't part of the API, how are we meant to disable the ripple effect on the chip? The solution above still spits out warnings which in turn make Jest fail

  console.error
    Warning: React does not recognize the `disableRipple` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `disableripple` instead. If you accidentally passed it from a parent component, remove it from the DOM element.