J
J
Juniorrrrr2021-06-04 15:06:06
typescript
Juniorrrrr, 2021-06-04 15:06:06

How to type reduce Typescript?

Tell me what TS scolds and how to fix it? Sandbox

60ba172ce127b058190748.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
wsdgsogjspm, 2021-06-04
@Juniorrrrr

const res = arr.reduce((acc, cur) => acc  + cur.counter, 0);

I
Ivan V, 2021-06-04
@verkhoturov

interface Counter {
   counter: number;
}

const arr: Counter[] = [{counter:120}, {counter:220}];

const res = arr.reduce((acc: number, cur: Counter) => {
    return acc  + cur.counter;
}, 0);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question