reactjs - 没有重载匹配此调用 - 宽度
问题描述
我正在尝试将此 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 设置最大固定宽度的替代方法吗?
解决方案
您可以向该属性添加maxWidth: "350px"
或任何您想要的值style
。但是,xs
和类似的尺寸属性旨在根据视口尺寸管理宽度。
推荐阅读
- database - Performing join on two big tables
- python - Discord.py[voice] giving installation error
- javascript - Chrome "request does not match recipient windows's origin"
- javascript - JavaScript Promise 如何执行它们的代码?
- java - 二维码 - dexing.DexArchiveMergerException
- gdb - 退出 .gdbinit
- java - 强制不变性
- sql - 为什么 SQL 中外连接的结果包含 null 列,而原始表没有?
- ruby-on-rails - RSpec/Capybara:设置一个经常调用的例程
- matlab - 使用 Matlab FFT 计算的频谱对于不同长度的样本(点数相同但 Fs 不同)给出的结果不一致?