You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[theme][typescript] Wrong types when using CSS Vars #49474
It is a bug. ThemeVars in createThemeFoundation.ts reuses the regular ZIndex interface, where everything is a number. But zIndex isn't excluded in shouldSkipGeneratingVar, so at runtime each theme.vars.zIndex.* is a string like 'var(--mui-zIndex-appBar, 1100)'.
theme.vars.opacity has the same problem. It's typed with the numeric Opacity interface but holds strings like 'var(--mui-opacity-inputPlaceholder, 0.42)'. I checked both with createTheme({ cssVariables: true }) on 9.4.0. theme.vars.shape.borderRadius is fine, it's already typed number | string.
Module augmentation won't get you around this, since merging interfaces can't change the type of a property that already exists. Until the types are fixed, use theme.zIndex.appBar if you need the actual number, or theme.vars.zIndex.appBar as unknown as string where you want the CSS variable.
Thank you. Indeed, more number properties that have a css variable value have that problem.
The as unknown as string workaround does work. The actual problem is that you need to be aware of the wrong type as code will happily compile while being buggy otherwise.
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.
@olivier-lxo Thanks again for creating this issue! If you have a moment, we would love to hear your thoughts on how we handled it with this short feedback form.
Activity
lazerg commentedon Oct 16, 2026
It is a bug.
ThemeVarsin createThemeFoundation.ts reuses the regularZIndexinterface, where everything is anumber. ButzIndexisn't excluded in shouldSkipGeneratingVar, so at runtime eachtheme.vars.zIndex.*is a string like'var(--mui-zIndex-appBar, 1100)'.theme.vars.opacityhas the same problem. It's typed with the numericOpacityinterface but holds strings like'var(--mui-opacity-inputPlaceholder, 0.42)'. I checked both withcreateTheme({ cssVariables: true })on 9.4.0.theme.vars.shape.borderRadiusis fine, it's already typednumber | string.Module augmentation won't get you around this, since merging interfaces can't change the type of a property that already exists. Until the types are fixed, use
theme.zIndex.appBarif you need the actual number, ortheme.vars.zIndex.appBar as unknown as stringwhere you want the CSS variable.olivier-lxo commentedon Oct 16, 2026
Thank you. Indeed, more
numberproperties that have a css variable value have that problem.The
as unknown as stringworkaround does work. The actual problem is that you need to be aware of the wrong type as code will happily compile while being buggy otherwise.[-]Wrong types when using CSS Vars[/-][+][theme][typescript] Wrong types when using CSS Vars[/+]github-actions commentedon Oct 19, 2026
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.
@olivier-lxo Thanks again for creating this issue! If you have a moment, we would love to hear your thoughts on how we handled it with this short feedback form.