R
R
Roman Yakimchuk2019-09-11 08:01:49
JavaScript
Roman Yakimchuk, 2019-09-11 08:01:49

How to determine the type of a variable in a loop?

Hello everyone,
There is a loop (TypeScript): How to determine the type for the variable `some`? It is impossible to take it out, the correct formation of the scope will be lost.
for (let some of data) { ... }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2019-09-11
@yakimchuk-ry

So it is necessary not for some, but for data to determine the type.

const myIterable: unknown = [1,2,3,4,5];

for (const entry of <IterableIterator<number>>myIterable) {
    console.log(entry);
}

Well, or as they wrote above, through typeguards.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question