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