Skip to content
Advertisement

Type json in React components

I have a dynamic json, for example:

JavaScript

And I created interface for this:

JavaScript

I have two components:

JavaScript

But this return me error:

Type “IResult” is not assignable to type ‘string’.

in line: <SecondComponent result={result}>

What I’m doing wrong?

Advertisement

Answer

When you pass arguments to a component, it is taken as props.

By defining SecondComponent as function SecondComponent(result: IResult) {}, you are declaring types of props as IResult and not the type of props.result as IResult.

Modify your declaration as following:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement