K
K
Konstantin2020-02-17 16:59:17
typescript
Konstantin, 2020-02-17 16:59:17

How to specify the type for destructuring?

For example, there is a line:

const [customLayer, map, layer, sidebarContentService] = actions;


How to specify the type for each variable inside []?

For example, I want the compiler to understand that map is a Map type. And that there are methods inside.

I tried like this:

const [customLayer, map<Map> as Map, layer, sidebarContentService] = actions;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Shvets, 2020-02-17
@Junart1

playground
It is necessary to specify the type for the whole pack as for tuple

V
Vasily Bannikov, 2020-02-17
@vabka

const ... = actions as [T1, T2, T3]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question