Type ‘{ children: string; key: string; }’ is not assignable to type ‘IntrinsicAttributes & FilterTagPropsType‘.
Property ‘childrendoes not exist on type ‘IntrinsicAttributes & FilterTagPropsType‘.ts(2322)

export const Filter: React.FC<PropsType&gt; = ({ title, tags }) =&gt; {
  return (
    <div&gt;
      <Text style={{ marginRight: 40, fontSize: 15, fontWeight: 500 }}&gt;
        {title} :{" "}
      </Text>
      {tags.map((t, index) => {
        if (index === tags.length - 1)
          return <FilterTag key={`filter${index}`}>{t}</FilterTag>;  // ====>报错
        return (
          <span key={`filter${index}`}>
            <FilterTag>{t}</FilterTag>
            <Divider type="vertical" />
          </span>
        );
      })}
    </div>
  );
};

解决办法:给子组件FilterTag手动加完善类型

interface FilterTagPropsType {
  children?: string;
  key?: string;
}

使用 TypeScript 开发 React 函数式组件-云海天教程 (yht7.com)

原文地址:https://blog.csdn.net/weixin_40282133/article/details/126874187

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_45980.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注