I am doing a loop on an Object using forEach or map.
However, I am getting a type error on the variable that I use to loop.
The error is Object is of type 'unknown'.
This occurs on val.name, val.title.
With .forEach
Object.entries(data).forEach(
([, val]) => {
newObject[val.name] = { // Object is of type 'unknown'
title: val.title // Object is of type 'unknown'
}}
)
With .map
Object.entries(data).map(
([, val]) => {
newObject[val.name] = { // Object is of type 'unknown'
title: val.title // Object is of type 'unknown'
}}
)
I tried to specify a type on the variable val such as:
([, val: any]) => {..my code..}
but it does not accept a type in that position