1

I do have an array of arrays full of objects for example as below

const array1: 
       any[] = 
            [
            {firstName: "John", lastName: "Doe"},
            {firstName: "Jane", lastName: "Doe"},
       ],
       [
            {firstName: "John", lastName: "Doe"},
       ],
       [
            {firstName: "Jane", lastName: "Doe"},
       ]
]

We do have a type restriction of using "any".

So would like to know what is the better way to define the type of array1.

1 Answer 1

3

Create an interface for the person objects (if you don't have one already), then use that

interface Person {
  firstName: string,
  lastName: string,
}

const array1: Person[][] = [[
  {firstName: "John", lastName: "Doe"},
  {firstName: "Jane", lastName: "Doe"},
], [
  {firstName: "John", lastName: "Doe"},
], [
  {firstName: "Jane", lastName: "Doe"},
]];
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.