B
B
bpGusar2018-09-24 20:54:29
typescript
bpGusar, 2018-09-24 20:54:29

How to specify types for an array in which an array, etc.?

for example

arr1: [
    {
      arr1info: [
        {
          arr1infocontent: "апвапва",
          arr1infoheading: "апвапва"
        },
        {
          arr1infocontent: "апвапва",
          arr1infoheading: "апвапва"
        },
        "foobar"
      ],
      arr1infoheading: "апвапва"
    },
    {
      arr1info: [
        {
          arr1infocontent: "апвапва",
          arr1infoheading: "апвапва"
        },
        {
          arr1infocontent: "апвапва",
          arr1infoheading: "апвапва"
        },
        "foobar"
      ],
      arr1infoheading: "апвапва"
    }
]

There is 1 array specified here, but there are many of them, and how can they all be assigned types?
Just started learning timescript and got stuck

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sh84, 2018-10-04
@sh84

interface Iarr2Info {[key: string]: string; }
type Info = (Iarr2Info|string)[];
interface Iarr1Info {[key: string]: string|Info; }

let arr1: Iarr1Info[] = [
  {
    arr1info: [
      {
        arr1infocontent: "апвапва",
        arr1infoheading: "апвапва"
      },
      {
        arr1infocontent: "апвапва",
        arr1infoheading: "апвапва"
      },
      "foobar"
    ],
    arr1infoheading: "апвапва"
  },
  {
    arr1info: [
      {
        arr1infocontent: "апвапва",
        arr1infoheading: "апвапва"
      },
      {
        arr1infocontent: "апвапва",
        arr1infoheading: "апвапва"
      },
      "foobar"
    ],
    arr1infoheading: "апвапва"
  }
];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question