4

How to pass object to child component in reactjs using tsx. I'm geting this error when I tried this way. Where I can declare the type? Property 'value' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<ShipmentCard>

Cards.tsx

  render() {
    return (
      <div>
        {this.state.card.map((card: any) => (
          <ShipmentCard key={card.id} value={card}/>
        ))}
      </div>
    );
  }

The full error message is:

Type '{ key: any; data: any; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly<{}> & Readonly<{ children?: ReactNode; }>'. Property 'data' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly<{}> & Readonly<{ children?: ReactNode; }>'

1
  • 2
    full error message Type '{ key: any; data: any; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<ShipmentCard> & Readonly<{}> & Readonly<{ children?: ReactNode; }>'. Property 'data' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<ShipmentCard> & Readonly<{}> & Readonly<{ children?: ReactNode; }>' Commented Aug 4, 2019 at 17:46

2 Answers 2

4

If you are using typescript then you have to declare all props in ShipmentCard.tsx

interface ShipmentCardProps {
    key: string;
    value: {}
}

interface ShipmentCardState {}

class ShipmentCard extends React.Component<ShipmentCardProps, ShipmentCardState> {
}
export default ShipmentCard
Sign up to request clarification or add additional context in comments.

1 Comment

@SKL Its great that i am able to help
0

Try this. have you 'card' in your state? It seems like no. You need to get props from parent component. You need to try pass data using props. So read the link. And try to use redux.

4 Comments

yes i did. When console.log this.props in render() it is showing empty object. tsx checking type thats why throwing this error
The object is empty twice? during mounting, it could be empty. What happened after update (second render)
If u pass an obejct in value attribute its throwing an error but value still showing console log. Error Property 'value' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<ShipmentCard> & Readonly<{}> & Readonly<{ children?: ReactNode; }>' This issue will be fixed if we fix type
stackoverflow.com/questions/48240449/… I have found this answer. It says: "You must give propTypes and stateType when you use typescript."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.