[英]ts(2322) Property children does not exist on type 'Intrinsic attributes and Props'
I'm getting the following error while trying to create a multimap with 'date' as the key and then iterate through the multimap which has arrays as it's values.我在尝试创建以“日期”为键的多重映射然后遍历以数组为值的多重映射时遇到以下错误。
Type '{children: never[];
输入'{children: never[]; key: string;
键:字符串; Index: string;
索引:字符串; Item: SomeItem[];
项目:SomeItem[]; }' is not assignable to type 'IntrinsicAttributes & Props'.
}' 不可分配给类型 'IntrinsicAttributes & Props'。 Property 'children' does not exist on type 'IntrinsicAttributes & Props'.
类型“IntrinsicAttributes & Props”上不存在属性“children”。 ts(2322)
TS(2322)
and not sure how to fix this不确定如何解决这个问题
const History = () => {
const [counter, setCounter] = useState(0);
type SomeMap = Map<string, SomeItem[]>;
let map: SomeMap = new Map();
//Items is of type SomeItem[]
Items.foreach((item) =>{
if(map.has(item.date)){
(map.get(item.date) ?? []).push(item);
}
else{
map.set(item.date,[item]);
}
});
return(
<Accordian>
{ map.foreach((value, index) => {
setCounter(counter +1 );
<Task
key={index}
Index={counter.toString()}
Item={value}>
</Task>
})}
</Accordian>
);
};
type Props = {
index: string;
Item: SomeItem[];
};
const Task = (props:Props) => {
const index = props.Index;
const Item = props.SomeItem;
render(/*Some Code*/);
};
Task
is not typed to receive children
, but actually you are actually passing a newline text node as the task's children. Task
没有输入来接收children
,但实际上您实际上是在传递一个换行文本节点作为任务的子节点。
<Task
key={index}
Index={counter.toString()}
Item={value}>{/* there is a new line text node here */}
</Task>
You probably want to make the JSX tag self closing to ensure it has no children:你可能想让 JSX 标签自动关闭以确保它没有子标签:
<Task
key={index}
Index={counter.toString()}
Item={value}
/>
In my case, Im using Styled Components and Primereact libraries.就我而言,我使用的是 Styled Components 和 Primereact 库。
The issue throw me when I create Style componet inheriting to a Primereact component (TabView), to solve this problem I add children as Styled Component Prop:当我创建继承到 Primereact 组件 (TabView) 的 Style 组件时,这个问题抛出了我,为了解决这个问题,我将子项添加为 Styled Component Prop:
import { TabView } from 'primereact/tabview';
import styled from 'styled-components';
type ChildrenProp = {
children: React.ReactNode;
};
export const ChatTabView = styled(TabView)<ChildrenProp>`
// css code
`;
I'ts because you have我不是因为你有
<ParentComponent prop1 prop2>
<div> With Child Components </div>
</ParentComponent>
In my case I leave alone my <ParentComponent prop1 prop2 />
and it works fine.在我的例子中,我不理会我的
<ParentComponent prop1 prop2 />
它工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.