How to pass JSON as a prop?

Viewed 2069

I have a component that gets 2 props, one is another component and the second is a JSON file:

interface HeaderProps {
  title: ReactElement<typeof Title>;
  data: any;
}

The prop 'title' is very specific and shows that only the component <Title /> can be passed there.

How can I specify the type of the prop data so instead of any it will be for JSON type only?

2 Answers

JSON in Typescript is just Object:

data: Object

I believe you are looking for an "object" with dynamic key of any type.

data: { [key:string]: any }// if array then {[key:string]: any}[]
Related