4

I would like to pass an array of objects from parent component to child component, but when I pass as props and declare interface on child component with expected types parent component gives error. How can I pass the data?

Here is the code to pass prop to a child called ConsultationCard

else if (check && st.length !== 0) {
   return <ConsultationCard itemData={items} />;
}

and parent component giving this error:

Type '({ id: number; title: string; client: string; due: string; count: number; amount: number; method: string[]; material: string[]; status: string; docs?: undefined; } | { id: number; title: string; client: string; ... 6 more ...; count?: undefined; })[]' is not assignable to type 'Data[]'

Child component has this type of interface and prop expectation:

interface Data {
  id: number;
  title: string;
  client: string;
  due: string;
  count: number;
  amount: number;
  method: string[];
  material: string[];
  status: string;
  docs?: number | undefined;
}
interface Props {
  itemData: Data[];
}
Mario Petrovic
  • 7,500
  • 14
  • 42
  • 62
  • 1
    In the error message, it shows `count?: undefined`. That doesn't match up with your type `Data`. Also, don't do `docs?: number | undefined`. It's already marked as optional, you don't need to specify `| undefined`. It's redundant. – rschristian Dec 23 '21 at 06:46
  • could you include an example of your `items`. – Saeed Shamloo Dec 23 '21 at 06:49
  • { "requests": [ { "id": 1, "title": "자동차 시제품 제작", "client": "A 고객사", "due": "2020.12.14", "count": 2, "amount": 100, "method": ["밀링", "선반"], "material": ["알루미늄"], "status": "대기중" }, here is the data of items – MukhammadBobur Dec 23 '21 at 07:31

0 Answers0