mui / mui/material-ui

Multiple themes with TypeScript merge declaration does not work properly

Open
#36,534 5 comments 0 reactions 1 assignee View on GitHub

@siriwatknp is already working on this.

Since Mar 16, 2023.

customization: theme scope: all components 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
Steps to reproduce 🕹

Link to live example:

Steps:

  1. Use Nx and generate one of several libraries
  2. Create multiple themes and use TypeScript merge declaration to get intellisense (as per the docs)
  3. As soon as you export multiple themes in your Nx monorepo, they will clash and TS will read all of them, meaning that for example if theme X has a "myVariant1" custom typography variant and theme Y has another, TS will read them all and want you to fill all of them out, in all of the themes.
Current behavior 😯

TypeScript is reading all of the merge declarations for all of your themes as soon as you export more than one theme.

Expected behavior 🤔

Types should be isolated to their theme and not exposed to the whole monorepo. Not sure how you'd solve this, but ideally you could look to other TypeScript solutions than merge declarations. Chakra UI does it by installing files into node_modules for example.

Context 🔦

We have a monorepo with many apps and many themes. We want full TypeScript support for all of them, but currently that's not really feasible if you use Nx at least.

Your environment 🌎
npx @mui/envinfo
  System:
    OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
  Binaries:
    Node: 18.13.0 - ~/.nvm/versions/node/v18.13.0/bin/node
    Yarn: 3.2.3 - ~/.nvm/versions/node/v18.13.0/bin/yarn
    npm: 8.19.3 - ~/.nvm/versions/node/v18.13.0/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: Not Found
  npmPackages:
    @emotion/react: ^11.7.1 => 11.7.1 
    @emotion/styled: ^11.6.0 => 11.6.0 
    @mui/base:  5.0.0-alpha.65 
    @mui/icons-material: ^5.4.4 => 5.4.4 
    @mui/material: ^5.3.0 => 5.3.0 
    @mui/private-theming:  5.3.0 
    @mui/styled-engine:  5.3.0 
    @mui/system:  5.3.0 
    @mui/types:  7.1.0 
    @mui/utils: ^5.3.0 => 5.3.0 
    @types/react: 18.0.1 => 18.0.1 
    react: ^18.1.0 => 18.1.0 
    react-dom: ^18.1.0 => 18.1.0 
    typescript: ^4.9.5 => 4.9.5

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.