After compiling typescript, ES6 Map.forEach is unexpectedly not a function

Exploring the new collection types introduced in ES6 for my TypeScript/React project.

interface MyComponentProps{
  myMap: Map<String, {isAvailable?: boolean}>,
}
...
this.props.myMap.keys();

Even though IntelliJ and Webpack compile the code without warnings, encountering a runtime error in Chrome 55.

this.props.myMap.forEach is not a function

tsconfig.json

{
"compilerOptions": {
"moduleResolution": "node",
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es6",
"jsx": "react"
  }
}

package.json

{
 "name": "cocktails-db",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
  "production": "webpack -p",
  "start": "webpack-dev-server -d",
  "test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
  "axios": "^0.15.3",
  "elasticsearch": "^12.1.0",
  "react": "^15.4.0",
  "react-bootstrap": "^0.30.7",
  "react-dom": "^15.4.0",
  "react-router": "^3.0.0",
  "react-router-bootstrap": "^0.23.1",
  "react-select2-wrapper": "^1.0.4-beta1"
},
"devDependencies": {
  "@types/axios": "^0.9.34",
  "@types/bootstrap": "^3.3.32",
  "@types/elasticsearch": "^5.0.1",
  "@types/react": "^0.14.51",
  "@types/react-bootstrap": "0.0.37",
  "@types/react-dom": "^0.14.19",
  "@types/react-router": "^2.0.41",
  "@types/react-router-bootstrap": "0.0.27",
  "html-webpack-plugin": "^2.24.1",
  "ts-loader": "^1.2.2",
  "typescript": "^2.0.10",
  "webpack": "^1.13.3",
  "webpack-dev-server": "^1.16.2"
}
}

Despite being able to utilize the Map type through the browser's console, suspecting an issue with TypeScript compilation. Potential missing dependency?

--- Edit --- Initialization problem identified, but unclear why there's no TypeScript feedback/type warning.

This is my usage of ´MyComponent´

myMap : any;
...
this.myMap="";
...
render() {
        return (
            <div>
                <MyComponent myMap={this.myMap}> </MyComponent>
            </div>
        )

Answer №1

The issue has been resolved; It was not actually a compilation problem, but rather a result of incorrect object initialization.

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

Having trouble uploading a file in PDF format (*.pdf)

I'm attempting to use Node's readFile method to read a file and then send it as a response so that the user can download it. This is the code snippet I have: async function(req, res, next) { const query = { id: req.params.id }; // @ts-ignore co ...

Is it possible to enable autocomplete for JavaScript generated code in .proto files?

I recently created a basic .proto file with the following content: syntax = "proto3"; message Event { optional string name = 1; } After downloading and installing the protoc linux compiler (protoc-3.19.3-linux-x86_64.zip) on my local machine, ...

Bootstrap typehead not activating jQuery AJAX request

I am attempting to create a Twitter Bootstrap typehead using Ajax, but nothing seems to be happening. There are no errors and no output being generated. Here is the jQuery Ajax code I have implemented: function CallData() { $('input.typeahea ...

Cautionary alert while displaying a data binding from a controller in AngularJS

Adding a numerical value to the controller: this.myValue = Number(elem.toFixed(2)); Then placing it inside an input form: <input class="my-input" type="number" value={{$ctrl.myValue}} ... > Although the value ...

Prevent the hiding of a select element with jQuery Chosen Select

I am facing difficulty hiding a select element with the chosen-select class if it does not have any elements present. I attempted: $("#Category2").hide(); and also tried removing the chosen-select class before hiding the element: $("#Category2").re ...

Thunk-based state access in Redux Toolkit

Is there a way to access the projectId value stored in state within a thunk, without passing it as a parameter when the action is called? interface RepoDetailsState { openIssuesCount: number error: string | null } const initialState: Rep ...

"Although Vuex data is present, an error is being logged in the JavaScript console

I'm utilizing Vuex to retrieve data from a URL and I need to use this data in computed properties in Vue.js. What could be causing the issue? <script> import {mapGetters, mapActions} from "vuex"; computed: { ...mapGetters(["ON ...

The issue with fetching user profile data on the client-side in Next.js 14

I've run into a problem with client-side data fetching on my Next.js 14 project. More specifically, I'm trying to retrieve user profile information from a backend API using Axios within a component, but for some reason, the data isn't coming ...

Reduce the version of NodeJs and express

At the moment, I am tackling a nodejs project. I have Express 3.X installed, which is currently in its alpha stage, and my node version is also at 0.7.2-pre. I am currently attempting to lower my express version through npm, but it appears that I also need ...

Utilizing jQuery to implement a CSS style with a fading effect, such as FadeIn()

I have a jQuery script that applies a CSS style to an HTML table row when the user clicks on a row link: $(this).closest('tr').css("background-color", "silver"); Is there a way to soften this color change effect, such as by gradually fading in ...

Issue with Mobile NavBar remaining visible after clicking on target element in HTML CSS

On my website, everything works perfectly with the Nav bar except for when I am on mobile. When I click on any href from my Nav Bar, it directs me to the correct location but does not close the Nav Bar afterward. I need it to function this way: After click ...

Stopping a jQuery function from executing multiple times while it is already active - is it possible?

Currently, I am utilizing the http://jsfiddle.net/CqAU2/ plugin for image rotation on my website. The issue I am facing is that when the user clicks on the image box multiple times, it continues rotating each time. I want the click action to only be regi ...

Error: Parsing error - Unrecognized character "@" in Angular module

Currently I am delving into the realm of webpack and attempting to integrate it into my project. However, I seem to have hit a roadblock as I encounter the following error. Despite my efforts to troubleshoot and research, I cannot seem to find a loader spe ...

What could be causing my Ajax success function to never fire?

My issue is that my $.ajax success function is not triggering. I simply need to execute a PHP file without passing or retrieving any values. I found an alternative method for reading values, but it cannot run because the function must be placed within th ...

JavaScript can be utilized to monitor outbound clicks effectively

I am currently working on implementing the code found at this link: Make a ping to a url without redirecting. The original poster is looking to ping a URL without opening multiple windows. My goal is to achieve the same functionality, but I also want to vi ...

Changing the color of an Angular <div> element with scripting

I am currently working on an Angular 6 project and I need to change the colors of a div tag from a script after a click function. However, I also need to change it back to transparent. When I click on the "Inheritance" option, the background color of the ...

Trouble with CSS full height implementation within a scrolling container

I have been grappling with this straightforward issue for quite some time now. It seems to be a unique problem as I couldn't uncover a similar one online. My goal is to set the height of the green bar to 100% (to match the height of the red parent el ...

Error encountered at the conclusion of input within a search button segment

I am currently in the process of developing a webpage that accepts a string input and then utilizes the Wikimedia API to search Wikipedia for 10 relevant pages. The issue I am facing lies within my JavaScript success function, where I intend to populate a ...

Undo changes in Sequelize transaction using a specific rollback target

In my current project, I am utilizing managed transactions. There is a specific scenario where I need to implement a single transaction and revert to a certain savepoint if it encounters an error, but still ensure that the changes are committed in the end. ...

How come the likes are not being refreshed when the button is clicked in my mongoose schema?

I am currently working on an express app using nodejs and mongoose. My main goal is to implement a JavaScript function that can update the number of likes on a post in a database directly from my ejs file. However, I have encountered troubles with this tas ...