【发布时间】:2021-09-14 04:54:52
【问题描述】:
<Grid item xs={12} align="center">
给我
No overload matches this call.
Overload 1 of 2, '(props: { component: ElementType<any>; } & Partial<Record<Breakpoint, boolean | GridSize>> & { alignContent?: GridContentAlignment | undefined; ... 7 more ...; zeroMinWidth?: boolean | undefined; } & CommonProps<...> & Pick<...>): Element', gave the following error.
Property 'component' is missing in type '{ children: Element; item: true; xs: 12; align: string; }' but required in type '{ component: ElementType<any>; }'.
Overload 2 of 2, '(props: DefaultComponentProps<GridTypeMap<{}, "div">>): Element', gave the following error.
Type '{ children: Element; item: true; xs: 12; align: string; }' is not assignable to type 'IntrinsicAttributes & Partial<Record<Breakpoint, boolean | GridSize>> & { alignContent?: GridContentAlignment | undefined; ... 7 more ...; zeroMinWidth?: boolean | undefined; } & CommonProps<...> & Pick<...>'.
Property 'align' does not exist on type 'IntrinsicAttributes & Partial<Record<Breakpoint, boolean | GridSize>> & { alignContent?: GridContentAlignment | undefined; ... 7 more ...; zeroMinWidth?: boolean | undefined; } & CommonProps<...> & Pick<...>'.ts(2769)
OverridableComponent.d.ts(17, 7): 'component' is declared here.
(JSX attribute) xs?: boolean | GridSize | undefined
请注意,我使用的是 tsx 顺便说一句,不知道为什么这会向我扔。我将文件扩展名更改为 jsx,一切正常(网格也来自材料 ui)
另外,问题出现在 `align="center" 部分,如果我删除不会出现错误
我也尝试将 align 更改为 alignItems 和 alignContent,从而解决了错误;但是它不会使内容与中心对齐
附带说明,不确定是否相关:在同一个文件中,我有一行:
<div style={{ align: "center" }}>
这也给我一个错误:
Type '{ align: string; }' is not assignable to type 'Properties<string | number, string & {}>'.
Object literal may only specify known properties, and 'align' does not exist in type 'Properties<string | number, string & {}>'.ts(2322)
index.d.ts(1760, 9): The expected type comes from property 'style' which is declared here on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'
【问题讨论】:
标签: css reactjs typescript material-ui