Error in Typescript: Issue with Object.fromEntries Typescript Error

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!!

Answer №1

Object.fromEntries first appeared in the ECMAScript 2019 standard, so make sure your lib option includes that version (or ES2020). Keep in mind that ESNext is constantly evolving.

On a side note, TypeScript v3.1.1 is considered outdated now. It's probably a good idea to consider upgrading to a newer version.

Answer №2

  • Make sure you are using TypeScript version 3.9

Locate and open the tsconfig.json file in your project directory

Insert the following configuration:

"target": "esnext",
"lib": ["esnext", "dom"]

Answer №3

To resolve the issue in your application, open the src/polyfills.ts file and make sure to uncomment the line:

import 'core-js/es/object';

This line should be placed before the zone.js import to address this particular problem. However, depending on the features and functionalities of modern browsers that your application utilizes, you may need to uncomment additional imports as well.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Enhance Bootstrap dropdown functionality in Angular 8

Currently, my project has numerous Bootstrap dropdowns which rely on jQuery. I am exploring the possibility of removing both jQuery and Bootstrap from my project. Can Angular Material dropdowns serve as a suitable replacement for Bootstrap dropdowns? Alt ...

Angular asynchronous testing with Observable using karma

I am currently working on testing an asynchronous scenario. Here is a snippet of my component: ngOnInit(private service: MyService) { this.isLoading = true; this.service.getData().subscribe((data) => { this.data = data; this.isLoa ...

What are some best practices for integrating ES2020 into an Angular project?

Below is the content of my tsconfig.json file: { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap&q ...

angular-in-memory-web-api encounters a 404 error

I recently completed the heroes tour and now I am trying to work on something similar, but I seem to be having trouble understanding angular-in-memory-web-api. Here is a snippet of my code: clients-data.service.ts import { Injectable } from '@angular/ ...

Encountering difficulty when trying to define the onComplete function in Conf.ts. A type error is occurring, stating that '(passed: any) => void' is not compatible with type '() => void'.ts(2322)'

I have been developing a custom Protractor - browserstack framework from the ground up. While implementing the onComplete function as outlined on the official site in conf.ts - // Code snippet to update test status on BrowserStack based on test assertion ...

Unveiling the Power of USSD Codes with Ionic Typescript: A Comprehensive Guide

Currently diving into the world of Ionic 2 Framework, I find myself on a quest to discover how to execute USSD codes in Ionic using Typescript. Any guidance or assistance from the community would be greatly appreciated! ...

Tips for differentiating function that accepts various types of arrays with generics

I have come across a typings declaration that caught my attention: public static Loop<Type>(arr:Type[], callback:(obj:Type) => void):void; This declaration represents the structure of a function written in native JavaScript. It essentially itera ...

TypeScript is unable to detect the .sequelizerc configuration file

I have a file called .sequelizerc which contains the following configuration: const path = require('path'); module.exports = { config: path.resolve('.', 'src/config/sequelizeCLIConfig.json'), 'migrations-path': ...

Angular 2 component encounters problem when exporting initialized interface

I'm facing a quirky issue. Within my component, I export some interfaces and when I attempt to use them without initializing, I encounter undefined errors, which is typical. Is there a more efficient way to initialize them without rewriting all that c ...

Exploring nested grandchildren components in Angular2 Dart

Currently, I am attempting to make the following code work in Angular2 Dart: <div class='test'> <accordion2> <accordion-item-2 title="blah" active="true"> <sample-form-1></sample ...

Learning how to use arrow functions with the `subscribe` function in

Can someone help clarify the use of arrow functions in TypeScript with an example from Angular 2's Observable subscribe method? Here's my question: I have code that is functional: this.readdataservice.getPost().subscribe( posts =&g ...

The TypeScript find() method on an array are showing an error message that says, "There is no overload that matches this call

Issue Description I encountered a problem while using TypeScript's find() method for an array. Whenever I input a value, it does not work properly and displays an error message stating, "No overload matches this call". Code Snippet addOption(event: ...

Compare the values of properties in an array with those in a separate array to filter in Angular/TypeScript

There are two arrays at my disposal. //1st array tasks.push({ ID: 1, Address: "---", Latitude: 312313, Longitude: 21312 }); tasks.push({ ID: 3, Address: "---", Latitude: 312313, Longitude: 21312 }); //2nd array agentTasks.push({ID:2,AgentID: 2,TaskID:1}); ...

When the down arrow key is pressed, the focus of the radio button is lost

I've been facing a persistent accessibility issue with the main-component in Angular. This component contains four different templates, but depending on the radio button selection, other templates are displayed. The problem arises when these templates ...

Making an Angular 6 HTTP GET call using HTTP-Basic authentication

When attempting to access a URL that requires Basic Authentication, and returns JSON data, what is the proper way to include my username and password in the following HTTP request? private postsURL = "https://jsonExample/posts"; getPosts(): Observable& ...

How to implement a Typescript interface without necessarily implementing the parent interfaces

Within my current project, I have defined the following interfaces: interface foo { fooProperty: number; fooFunction(): void; } interface bar extends foo { barProperty: string; barFunction(): void; } Now, I am interested in creating a class like ...

The 'formGroup' property cannot be bound as it is not recognized as a valid property of 'form' in Angular 7

I tried implementing a login feature using web API with Angular 7, but encountered an error when using <form [formGroup]="loginForm" (submit)="loginFormSubmit()">. What could be causing this issue? https://i.sstatic.net/3M2a5.jpg login.component.ht ...

Disconnecting a Metamask Wallet in an Angular application: A Step-by-

I need assistance with disconnecting a Metamask wallet using web3 in Angular. //this is my wallet connection code async connectWallet() { const accounts = await this.ethereum.request({ method: 'eth_requestAccounts', }); this.selectedAddress ...

Unveiling the mysteries of abstract classes in TypeScript

I have a collection of different animal classes, all derived from a common abstract base class. To illustrate: abstract class Animal { abstract speak(): string; } class Dog extends Animal { speak(): string { return "woof... sigh" } } ...

Validation of passwords in reactive forms using Angular Material Design Lite

I have a password field with specific validation requirements: The password must be alphanumeric It cannot consist solely of characters or numbers <p> <mdl-textfield label="Password" ...