首页 > 解决方案 > 升级到 rc.0 时 Material-UI v5 typescript 错误

问题描述

我刚刚将我的 material-ui 升级到 v5-rc.0 并尝试使用styled-components. 但是,在我的Component.styles.ts文件中出现错误:

如果不引用“@mui/material/node_modules/@types/react”,则无法命名推断的“StyledStepper”类型。这可能是不可移植的。类型注释是必要的。

这是我的文件:

import { styled } from '@mui/material/styles';
import Stepper, { stepperClasses } from '@mui/material/Stepper';
import StepConnector, { stepConnectorClasses } from '@mui/material/StepConnector';
import { stepLabelClasses } from '@mui/material/StepLabel';

export const StyledStepper = styled(Stepper)(({ theme }) => ({
  [`&.${stepperClasses.alternativeLabel}`]: {
    [`.${stepLabelClasses.root}`]: {
      flexDirection: 'column-reverse',
    },
...

有谁知道这个错误是什么意思?

标签: typescriptmaterial-ui

解决方案


将样式从另一个文件传递给sx道具时,我遇到了类似的问题

我发现的是这个我不确定它是否有帮助,但看看

我必须导出每种样式,as const就像这样:

export const  logoHeadersContainer= {
    flexDirection: 'column',
    alignItems: 'center',
  } as const;

推荐阅读