简体   繁体   English

ts(2322) 属性子项在类型“内在属性和道具”上不存在

[英]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}
      />

Playground 操场

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.

相关问题 MUI v5 属性“fullWidth”在类型“IntrinsicAttributes &amp; { theme: Theme;”上不存在。 } &amp; { 孩子?:ReactNode; }&#39;。 TS2322 - MUI v5 Property 'fullWidth' does not exist on type 'IntrinsicAttributes & { theme: Theme; } & { children?: ReactNode; }'. TS2322 类型'IntrinsicAttributes &amp; UserSelectProps &amp; { children?: ReactNode; 上不存在属性'isMulti' }'.ts(2322) - Property 'isMulti' does not exist on type 'IntrinsicAttributes & UserSelectProps & { children?: ReactNode; }'.ts(2322) 类型“IntrinsicAttributes &amp; TableProp”.ts(2322) 上不存在属性“prop” - Property 'prop' does not exist on type 'IntrinsicAttributes & TableProp'.ts(2322) 类型“IntrinsicAttributes”上不存在属性“isOpen”。 ts(2322) - Property 'isOpen' does not exist on type 'IntrinsicAttributes. ts(2322) 类型“HTMLAttributes”上不存在属性“X”<htmldivelement> '.ts(2322)</htmldivelement> - Property 'X' does not exist on type 'HTMLAttributes<HTMLDivElement>'.ts(2322) 如何在Typescript中为其子项设置功能道具类型? TS2339类型上不存在“孩子”属性 - How to set function props type for its child in Typescript? Property 'children' does not exist on type TS2339 类型 {} 不可分配给类型内在属性和道具 React + TS - Type {} is not assignable to type intrinsic attributes and props React + TS 类型“IntrinsicAttributes &amp; RefAttributes”上不存在属性“item” <Component<{}, any, any> &gt;&#39;.ts(2322) - Property 'item' does not exist on type 'IntrinsicAttributes & RefAttributes<Component<{}, any, any>>'.ts(2322) 错误 TS2322:“DetailedHTMLProps”类型上不存在属性“css” <htmlattributes<htmldivelement> , HTMLDivElement&gt;' </htmlattributes<htmldivelement> - error TS2322: Property 'css' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>' TS2339:“家”类型上不存在属性“道具” - TS2339: Property 'props' does not exist on type 'Home'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM