A
A
asdasdqwe2022-03-04 19:40:07
typescript
asdasdqwe, 2022-03-04 19:40:07

How to set the type recursively?

[{
    id: 1,
    name: "products",
    children: [
      { id: 3, name: "all products" },
      { id: 4, name: "new product"},
    ],
  }]


I wrote:
interface props{
  list: {id: number; name: string; children?: any}[];   // Что написать вместо any?
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2022-03-04
@asdasdqwe

interface Props {
  list: {
    id: number;
    name: string;
    children?: Props['list'];
  }[];
}

or
interface PropsListItem {
  id: number;
  name: string;
  children?: PropsListItem[];
}

interface Props {
  list: PropsListItem[];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question