小编Geo*_*geK的帖子

Material UI 样式组件 - “如果没有引用,X 的推断类型就无法命名......”

这个TS问题如何解决?我的样式组件从文件中导出style.ts并在我的 React 组件的文件中使用index.tsx

样式.ts:

import { styled, Theme } from '@mui/material/styles';

type CardProps = {
    theme?: Theme;
    selected: boolean;
};

const Card = styled('div', {
    shouldForwardProp: (p) => !!p
})(({ theme, selected }: CardProps) => ({
    display: 'flex',
    flexDirection: 'column',
    padding: theme?.spacing(2),
    width: theme?.spacing(39.5),
    boxShadow: theme?.shadows[2],
    color: theme?.palette.grey[50],
    borderRadius: theme?.spacing(0.5),
    margin: `${theme?.spacing()} ${theme?.spacing(2)}`,
    ...(selected && {
        background: theme?.palette.grey[100],
        color: theme?.palette.getContrastText(theme?.palette.grey[100])
    }),
    ...(!selected && {
        cursor: 'pointer',
        border: `1px solid #DEE4EA`
    }),
    '&:hover': {
        ...(!selected && { …
Run Code Online (Sandbox Code Playgroud)

types typescript reactjs material-ui styled-components

5
推荐指数
2
解决办法
4325
查看次数