0

I am expecting the following example JSON response from API, and I am trying to make an interface for it.

{
  types: [
    {
      id: 1,
      contents: [
        {
          id: 1001,
          perishable: 0
        },
        {
          id: 1002,
          perishable: 0
        }
      ]
    }
  ]
}

Here is how I am trying to define the interface, but I am not sure if I am doing this right. Basically, the response I get back is "types" which is an array of objects, and each object inside it has an array called "contents". Also, how to say something is an array of objects?

export interface Types {
  id: string;
  contents: Array<any>;
}

Is that right?

1 Answer 1

2

You can use any if you want, but you can be more specific:

interface Content {
    id: number;
    perishable: number;
}

interface Type {
    id: number;
    contents: Content[];
}

interface Response {
    types: Type[];
}
Sign up to request clarification or add additional context in comments.

Comments

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.