【问题标题】:Typescript error: is not assignable to type 'IntrinsicAttributes'. Property 'children' does not exist on type 'IntrinsicAttributes'打字稿错误:不可分配给类型“IntrinsicAttributes”。 “IntrinsicAttributes”类型上不存在属性“children”
【发布时间】:2021-10-29 06:47:25
【问题描述】:

我创建了一个弯曲的容器,我尝试在我的项目中使用它,但是报错,我不知道如何解决,有没有人有什么想法?

import Image from "next/image";
import curveImage from "/public/curve.png";
import curveReverseImage from "/public/curve-reverse.png";
import curveImageBlack from "/public/curve-black.png";
import curveReverseImageBlack from "/public/curve-reverse-black.png";

type Props = {
  children: JSX.Element;
  curveTop?: "white" | "black" | "none";
  curveBottom?: "white" | "black" | "none";
  [defaultParam: string]: any;
};

export default function CurvedContainer({
  children,
  curveTop = "white",
  curveBottom = "white",
  ...rest
}: Props) {
  return (
    <div {...rest} className={`${rest.className} flex flex-col`}>
      {curveTop != "none" && (
        <div className="curveTop" style={{ marginTop: -1 }}>
          <Image
            height="250"
            alt="top image"
            src={
              curveTop == "white" ? curveReverseImage : curveReverseImageBlack
            }
          />
        </div>
      )}

      {children}

      {curveBottom != "none" && (
        <div className="curveTop -mb-2">
          <Image
            height="250"
            alt="top image"
            src={curveBottom == "white" ? curveImage : curveImageBlack}
          />
        </div>
      )}
    </div>
  );
}

我不知道为什么会不幸出现此错误。如果有人可以帮助我,那就太棒了!

 <Container
    className="none"
    curveTop="white"
    curveBottom="none"
  >
    <div className="flex flex-row items-center justify-center p-8">
      <a href="#" className={`bg-black text-white font-bold
         tracking-wider text-sm text-center uppercase rounded-full px-8 py-2 shadow-lg `}
        type="button">
        Saiba Mais
      </a>
    </div>
 </Container>

这里有错误:

【问题讨论】:

    标签: reactjs typescript react-props children


    【解决方案1】:

    最好将 React.ReactNode 类型用于反应元素,因为它也适用于元素数组。 只需更改您的类型

    children: JSX.Element;
    

    React.ReactNode

    【讨论】:

    • 我试过了,但错误仍然存​​在,同样的错误,还有其他想法吗?
    【解决方案2】:

    您的Container 组件具有childrencurveTopcurveBottom 属性 当您调用Container 组件时,您不会传递children。也尝试传递这个道具。

    【讨论】:

      猜你喜欢
      • 2020-09-15
      • 2021-09-11
      • 2020-09-03
      • 2022-08-18
      • 2018-10-24
      • 2020-08-25
      • 2022-12-09
      • 2021-07-12
      • 2021-08-20
      相关资源
      最近更新 更多