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

TS2339: Property theme does not exist on type ThemeArg trying to use callback themes #235

Open
bexsoft opened this issue Sep 13, 2024 · 2 comments
Assignees
Labels
customization: theme Centered around the theming features package: system Specific to @mui/system status: waiting for maintainer These issues haven't been looked at yet by a maintainer

Comments

@bexsoft
Copy link

bexsoft commented Sep 13, 2024

Steps to reproduce

TS2339: Property theme does not exist on type ThemeArg TS error is seen while trying to use the theme callback variables as stated in readme document using Vite

Steps to Reproduce:

  1. Create a theme in pigment plugin inside vite.config.ts:
plugins: [
        pigment({theme: extendTheme({
                bgColor: "#f09",
                fontColor: "#000",
                borderColor: "#cdcdcd"
            })}),
        react(),
...
  1. Go into your component file (in my case Box/index.tsx) and create a a Base component using the styled API and a callback function with theme as recommended in the mentioned README document
import {styled} from "@pigment-css/react";

const ButtonBase = styled('button')(({theme}) => ({
    padding: '10px 20px',
    borderRadius: 5,
    border: 'none',
    backgroundColor: 'blue',
    color: theme.bgColor,
    cursor: 'pointer',
    '&:hover': {
        backgroundColor: 'darkblue',
        border: `1px solid ${theme.borderColor}`
    }
}));
  1. Observe that TS2339: Property theme does not exist on type ThemeArg error is seen in the editor and while trying to build the library by using yarn build in the vite env:
Screenshot 2024-09-12 at 9 38 02 p m Screenshot 2024-09-12 at 9 39 56 p m

Current behavior

TS2339: Property theme does not exist on type ThemeArg error is seen during development & build. If the // @ts-expect-error comment comment is added, then the compiler and the build allows to continue and access the theme variables

Expected behavior

No errors should be seen

Context

No response

Your environment

npx @mui/envinfo
  System:
    OS: macOS 14.6.1
  Binaries:
    Node: 22.4.1 - ~/.nvm/versions/node/v22.4.1/bin/node
    npm: 10.8.1 - ~/.nvm/versions/node/v22.4.1/bin/npm
    pnpm: Not Found
  Browsers:
    Chrome: 128.0.6613.138
    Edge: 128.0.2739.79
    Safari: 17.6
  npmPackages:
    @emotion/react:  11.13.3 
    @emotion/styled:  11.13.0 
    @mui/private-theming:  6.1.0 
    @mui/styled-engine:  6.1.0 
    @mui/system:  6.1.0 
    @mui/types:  7.2.16 
    @mui/utils:  6.1.0 
    @pigment-css/react:  0.0.22 
    @pigment-css/vite-plugin: ^0.0.22 => 0.0.22 
    @types/react: ^18.3.3 => 18.3.5 
    react: ^18.3.1 => 18.3.1 
    react-dom: ^18.3.1 => 18.3.1 
    typescript: ^5.5.3 => 5.6.2 

Chrome Version 128.0.6613.121 (Official Build) (arm64)
tsconfig.json
{
  "compilerOptions": {
    "target": "ES2020",
    "useDefineForClassFields": true,
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "module": "ESNext",
    "skipLibCheck": true,

    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "isolatedModules": true,
    "moduleDetection": "force",
    "noEmit": true,
    "jsx": "react-jsx",

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true
  },
  "extends": "./tsconfig.json",
  "include": ["lib"]
}

Search keywords: theme ThemeArg callback

@bexsoft bexsoft added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 13, 2024
@zannager zannager added package: system Specific to @mui/system customization: theme Centered around the theming features labels Sep 13, 2024
@brijeshb42
Copy link
Contributor

@siriwatknp Could you link to the doc or example where we augment the theme types ?

@brijeshb42
Copy link
Contributor

@bexsoft Could you try to augment the types by referring to this example ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: theme Centered around the theming features package: system Specific to @mui/system status: waiting for maintainer These issues haven't been looked at yet by a maintainer
Projects
None yet
Development

No branches or pull requests

4 participants