C
C
chelnokov_a2021-07-22 10:23:36
typescript
chelnokov_a, 2021-07-22 10:23:36

How to fix typescript error?

Good afternoon.

There is an array Product[]. Also there is an object containing Record

The array at me ordered. The task is to collect an array from an object with the same sequence as the presented array. The task itself is not difficult, I solved it like this:

const result = dataProduct.products.map((item) => ({
       ...item,
       ...data[item.id]
}));


The problem is that I get this error

Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'xhr>'.

Please help me figure out how to fix

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-07-22
@Aetae

...data[String(item.id)]?
Your most important piece of code is missing:

type 'xhr>'.
, as I understand it, there really is Record<что-то, что-то xhr>.
And that is exactly where the answer to your question lies.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question