首页 > 解决方案 > 没有重载匹配此调用 - 宽度

问题描述

我正在尝试将此 React JS 重写为打字稿:https ://codesandbox.io/s/pedantic-violet-yklku

当我尝试更改此行时出现错误:

            <Grid
                spacing={0}
                container
                direction="row"
                xs={3}
                className={classes2.color}
                width={2}
                style={{ height: "100%", overflow: "auto" }}
            >

我得到错误:

TS2769: No overload matches this call.   Overload 1 of 2, '(props: { component: ElementType<any>; } & { alignContent?: GridContentAlignment | undefined; alignItems?: GridItemsAlignment | undefined; ... 13 more ...; zeroMinWidth?: boolean | undefined; } & CommonProps<...> & Pick<...>): Element', gave the following error.     Property 'component' is missing in type '{ children: Element[]; spacing: 0; container: true; direction: "row"; xs: 3; className: string; width: number; style: { height: string; overflow: "auto"; }; }' but required in type '{ component: ElementType<any>; }'.   Overload 2 of 2, '(props: DefaultComponentProps<GridTypeMap<{}, "div">>): Element', gave the following error.     Type '{ children: Element[]; spacing: 0; container: true; direction: "row"; xs: 3; className: string; width: number; style: { height: string; overflow: "auto"; }; }' is not assignable to type 'IntrinsicAttributes & { alignContent?: GridContentAlignment | undefined; alignItems?: GridItemsAlignment | undefined; ... 13 more ...; zeroMinWidth?: boolean | undefined; } & CommonProps<...> & Pick<...>'.       Property 'width' does not exist on type 'IntrinsicAttributes & { alignContent?: GridContentAlignment | undefined; alignItems?: GridItemsAlignment | undefined; ... 13 more ...; zeroMinWidth?: boolean | undefined; } & CommonProps<...> & Pick<...>'.

当我删除width它的工作。您知道为 Grid 设置最大固定宽度的替代方法吗?

标签: reactjsmaterial-uireact-typescriptreact-material

解决方案


您可以向该属性添加maxWidth: "350px"或任何您想要的值style。但是,xs和类似的尺寸属性旨在根据视口尺寸管理宽度。


推荐阅读