mui / mui/material-ui

Multiple declare module '@mui/material/Button' don't work

Open
#31,366 9 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

scope: all components type: bug typescript
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Duplicates
  • I have searched the existing issues
Latest version
  • I have tested the latest version
Current behavior 😯

The current advise is to use the following code

declare module '@mui/material/Button' {
  interface ButtonPropsVariantOverrides {
    pill2: true
  }
}

This works if they are in the same file, you can see that pill2 is recognized:
Schermafbeelding 2022-03-08 om 14 04 14

If I move the second declaration to another file it isn't picked up anymore:
Schermafbeelding 2022-03-08 om 13 54 03

If I replace the import paths with '@mui/material/Button/Button' it works as expected:
Schermafbeelding 2022-03-08 om 13 56 06

Expected behavior 🤔

The documentation should probably advise the following code:

declare module '@mui/material/Button/Button' {
  interface ButtonPropsVariantOverrides {
    pill2: true
  }
}
Steps to reproduce 🕹

See screenshots in Current behavior.

Context 🔦

We have some base declarations we want to make and allow 'implementors' add new declarations.

Your environment 🌎
`npx @mui/envinfo`
 System:
    OS: macOS 12.2.1
  Binaries:
    Node: 14.19.0 - ~/.nvm/versions/node/v14.19.0/bin/node
    Yarn: 1.19.1 - ~/.nvm/versions/node/v14.19.0/bin/yarn
    npm: 6.14.16 - ~/.nvm/versions/node/v14.19.0/bin/npm
  Browsers:
    Chrome: 99.0.4844.51
    Edge: 99.0.1150.36
    Firefox: Not Found
    Safari: 15.3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using two separate TypeScript declaration files for '@mui/material/Button', then compare that result with the '@mui/material/Button/Button' path shown in the report. Start by examining the module-augmentation guidance referenced in the issue; done means the documented declaration path works when declarations are split across files.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.