In my TypeScript code, I have a function that utilizes Object.fromEntries to simplify a complex response object and organize it by using a substring of the child object key.
let Newresult = res.map(object => Object.fromEntries(Object.entries(object).map(([key, value]) => [
key,
value.map(valueobject => Object.entries(valueobject).reduce((res1, [name, value]) => {
const key = name.slice(0, 5);
res1[key] = res1[key] || {};
res[key][name] = value;
return res1;
}, {}))
])));
However, when I try to compile, TypeScript throws the following errors:
error TS2339: Property 'fromEntries' does not exist on type 'ObjectConstructor'.
error TS2339: Property 'map' does not exist on type '{}'.
I attempted to update my tsconfig.json lib-array with ESNext,ES2017.Object, but the compilation error persists. Interestingly, adding these updates allows me to use Object.entries without any issues.
My environment includes Angular version 6 and TypeScript version 3.1.1
Could someone suggest an alternative method to achieve the desired outcome as described above?
Thank you in advance!!