Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[material-ui] Using variant props callback errors in TypeScript #40671

Closed
maddrag0n opened this issue Jan 18, 2024 · 1 comment · Fixed by #40946
Closed

[material-ui] Using variant props callback errors in TypeScript #40671

maddrag0n opened this issue Jan 18, 2024 · 1 comment · Fixed by #40946
Assignees
Labels
bug 🐛 Something doesn't work customization: theme Centered around the theming features package: material-ui Specific to @mui/material typescript

Comments

@maddrag0n
Copy link

maddrag0n commented Jan 18, 2024

Related page

https://mui.com/material-ui/customization/theme-components/#creating-new-component-variants

Kind of issue

Missing information

Issue description

When customizing component variants using the createTheme approach, using a callback for variant props results in a TS error:

Type '(props: ButtonProps<"button", {}>) => "inherit" | "primary" | "secondary" | "success" | "error" | "info" | "warning" | undefined' has no properties in common with type 'Partial<ButtonProps<"button", {}>>'.ts(2559)

This seems to happen because OverridableTypeMap has props typed to {} and props => ({}) does not satisfy {}.

I assume I need to do some type of module augmentation, however I am not completely sure at which level (without breaking other stuff).

Example:

const theme = createTheme({
  components: {
    MuiButton: {
      variants: [{
        props: (props: ButtonProps) => props.color !== 'primary',
        style: ({ theme: { palette } }) => ({
          backgroundColor: palette.grey[500],
        }),
      }]
    }
  }
})

EDIT: For anyone running into the same issue, ugly typecasting works (but is not a viable solution)

{ props: (({ color }: ButtonProps) => color !== 'secondary') as Partial<ButtonProps<"button", {}>> }

Context

  • Typescript 4.9

Search keywords: customization:theme, typescript, support:question

@maddrag0n maddrag0n added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: docs-feedback Feedback from documentation page labels Jan 18, 2024
@zannager zannager added typescript customization: theme Centered around the theming features labels Jan 18, 2024
@danilo-leal danilo-leal changed the title Using variant props callback errors in typescript [material-ui] Using variant props callback errors in TypeScript Jan 18, 2024
@danilo-leal danilo-leal added the package: material-ui Specific to @mui/material label Jan 18, 2024
@ZeeshanTamboli ZeeshanTamboli added bug 🐛 Something doesn't work and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: docs-feedback Feedback from documentation page labels Feb 3, 2024
@ZeeshanTamboli
Copy link
Member

Looks like a bug. I'll create a PR soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work customization: theme Centered around the theming features package: material-ui Specific to @mui/material typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants