0
votes

I'm passing props from parents to child using typescript: This is child component

interface CarouselItemProps {
  interval: number;
  src: string;
  alt: string;
  title: string;
  p: string;
  btn: string;
}

const CarouselItem:FC<CarouselItemProps> = (props: CarouselItemProps) => {
  return (
    <>
      <Carousel.Item interval={props.interval}>
        <img
          className="d-block w-100 carousel-img"
          src={props.src}
          alt={props.alt}
        />
        <Carousel.Caption>
          <h1 className="carousel-title">{props.title}</h1>
          <p className="carousel-p">{props.p}</p>
          <Button variant="primary" className="btn-contact-us">
            {props.btn}
          </Button>
        </Carousel.Caption>
      </Carousel.Item>
    </>
  );
};

export default CarouselItem;

And parent component:

  <Carousel>
    <CarouselItem interval={1000} 
      src="/images/banner-home.png" 
      alt="First slide"
      title="A company with industrial network 4.0"
      p="We provide technology solutions that serve business and life
      demands in the time of the technology boom with a young and
      dynamic internal force to keep abreast of the development trend of
      information society"
      btn="Contact Us"
    />

But I got the error at src="/images/banner-home.png" in parent component:

Type '{ interval: number; src: string; alt: string; title: string; p: string; btn: string; }' is not assignable to type 'IntrinsicAttributes & Omit<Pick<DetailedHTMLProps<HTMLAttributes, HTMLDivElement>, "key" | keyof HTMLAttributes<...>> & { ...; }, BsPrefixProps<...> & CarouselItemProps> & BsPrefixProps<...> & CarouselItemProps & { ...; }'. Property 'src' does not exist on type 'IntrinsicAttributes & Omit<Pick<DetailedHTMLProps<HTMLAttributes, HTMLDivElement>, "key" | keyof HTMLAttributes<...>> & { ...; }, BsPrefixProps<...> & CarouselItemProps> & BsPrefixProps<...> & CarouselItemProps & { ...; }'

Anyone knows how to solve this problem?

2
I read the above post and still don't know how to fix my problem. Can you explain clearer about how to solve this error? - mrSmith91

2 Answers

1
votes

I made a huge mistake: I imported CarouselItem from react-bootstrap instead of from my own component

0
votes

Looking at the phrase in error Property 'src' does not exist on type 'IntrinsicAttributes..... I suspect attribute src is the specific to HTML elements like img so changing this name from src to something else may work fine.

Try changing src to srcImage in your interface and while passing parent component.

Note: This answer is not tested.