0

Objective

Build an interface that inside will have telephone_array. I know that my telephone_array is an array that has many objects inside.

enter image description here

Interfaces that I have

interface Client {
  id: string;
  name: string;
  email: string;
  telephone: string;
  created_at: string;
}


interface ClientsResponse {
  clients: Client[];
}

I would like to know how can I put the telephone_array inside the interface.

3 Answers 3

2

You can add array of objects like so:

interface Client {
  id: string;
  name: string;
  email: string;
  telephone: string;
  created_at: string;
  telephone_array: Array<{
     id: string;
     telephone_number: string;
  }>
}

or

telephone_array: {
     id: string;
     telephone_number: string;
  }[]
Sign up to request clarification or add additional context in comments.

Comments

1

Something like this

interface Client {
  id: string;
  name: string;
  email: string;
  telephone: string;
  created_at: string;
  telephone_array: {
     id: string;
     telephone_number: string;
  }[];
}

Comments

0

Just use another interface as an array:

interface Telephone {
  id: string;
  telephone_number: string;
}

interface Client {
  id: string;
  name: string;
  email: string;
  telephone: string;
  created_at: string;
  telephone_array: Telephone[];
}

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.