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

[TypeScript] Cannot override TextField variant with custom theme #32659

Closed
2 tasks done
fzaninotto opened this issue May 6, 2022 · 3 comments
Closed
2 tasks done

[TypeScript] Cannot override TextField variant with custom theme #32659

fzaninotto opened this issue May 6, 2022 · 3 comments
Assignees
Labels
component: text field This is the name of the generic UI component, not the React module! typescript

Comments

@fzaninotto
Copy link
Contributor

fzaninotto commented May 6, 2022

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

When creating a custom theme with a variant for the TextField default props, TypeScript refuses to compile:

import { createTheme } from '@mui/material/styles';

const theme  = {
  components: {
     MuiTextField: {
          defaultProps: {
              variant: 'filled',
          },
      },
   }
};

const foo = createTheme(theme);

The error is:

Argument of type '{ components: { MuiTextField: { defaultProps: { variant: string; }; }; }; }' is not assignable to parameter of type 'ThemeOptions'.
  The types of 'components.MuiTextField.defaultProps' are incompatible between these types.
    Type '{ variant: string; }' is not assignable to type 'Partial<TextFieldProps> | undefined'.
      Type '{ variant: string; }' is not assignable to type 'Partial<OutlinedTextFieldProps>'.
        Types of property 'variant' are incompatible.
          Type 'string' is not assignable to type '"outlined"'.

Expected behavior 🤔

Being able to override the variant without error

Steps to reproduce 🕹

Open the following URL on the TypeScript playground:

https://www.typescriptlang.org/play?ts=4.6.2&ssl=13&ssc=32&pln=1&pc=1#code/JYWwDg9gTgLgBAbzgYygUwIYzQFQBZohpwC+cAZlBCHAOQACIArsAPQhZpTAYA2tAKAHIIAOwDO8GASJw4AXkQC5I8GLSiY4gFxK5+gLIscaAB4wAYsDS8AJroTL9zubbTkMTXjAAKVMDp6LsFyAG4Y3BiaurTkwLy8aLa0ADROIaRpwSRZciQCJADcQiIS8OQQEAoo6Jz4hGgAFNINAJSFQA

Context 🔦

I want to allow global variant override of text fields via theme in react-admin

Your environment 🌎

`npx @mui/envinfo`
  System:
    OS: macOS 12.2.1
  Binaries:
    Node: 14.19.1 - ~/.nvm/versions/node/v14.19.1/bin/node
    Yarn: 1.22.15 - ~/.nvm/versions/node/v14.19.1/bin/yarn
    npm: 6.14.16 - ~/.nvm/versions/node/v14.19.1/bin/npm
  Browsers:
    Chrome: 101.0.4951.54
    Edge: Not Found
    Firefox: Not Found
    Safari: 15.3
@fzaninotto fzaninotto added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 6, 2022
@fzaninotto
Copy link
Contributor Author

@ScreamPlasmax Thanks a lot, that solved my problem! I'll close the issue.

I know this isn't a MUI problem, but the TS errors are cryptic enough to justify a quick note in the MUI documentation.

@siriwatknp siriwatknp added bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! typescript and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jun 20, 2022
@ZeeshanTamboli
Copy link
Member

We can close this issue as this is not a MUI problem but a TypeScript limitation. Similar to #15697 to some extent.

@ZeeshanTamboli ZeeshanTamboli removed the bug 🐛 Something doesn't work label Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! typescript
Projects
None yet
Development

No branches or pull requests

5 participants