Home > Mobile >  MUI styled TS Error : No overload matches this call
MUI styled TS Error : No overload matches this call

Time:12-26

I am getting this error:

No overload matches this call.

How to resolve this error?

I am trying to create custom button. I am able to create button but getting above error.

Here is my code:

enter image description here

any idea??

CodePudding user response:

Besides the typo, the issue is that your getStyles function returns a general object, whereas MUI styled expects a CSSObject (or, to be more accurate, in your case, a function that returns said CSSObject).

The styled function is powerful with a lot of overloads and complex types, but the drawback is indeed that the error message might be so big that it does not fit in the preview, making it difficult to pinpoint the root cause of the problem.

In your case, you can fix it by typing as CSSObject instead of plain object:

import { CSSObject } from "@mui/material/styles";

const commonStyle: CSSObject = {}; // Instead of `object` type

Playground Link

  • Related