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)

发表回复

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