I have a function in typescript which uses Object.fromEntries to reduce a complex response object and group it using 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;
}, {}))
])));
but the problem is typescript throws below error while compiling.
error TS2339: Property 'fromEntries' does not exist on type 'ObjectConstructor'.
error TS2339: Property 'map' does not exist on type '{}'.
I tried adding ESNext,ES2017.Object into my tsconfig.json lib-array but still its throwing compilation error. but the same updates for my lib-array is allowing me to use Object.entries.
I am using angular -v-6, typescript:~3.1.1
which other method can help me achieve the same result as above. can somebody direct me in right direction?
Thanks in advance!!
Open tsconfig.json
Add
"target": "esnext",
"lib": ["esnext", "dom"]
Object.fromEntries
was ES2019, so your lib
option needs to include that (or ES2020). (ESNext is a moving target.)
That said, TypeScript v3.1.1 is fairly old. You may need to upgrade.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With