While attempting to convert the JS code from 'AMcharts4 codepen pre selecting areas' into ES6, I encountered an error.
Error TS2339: Property 'selected' does not exist on type 'Object'.
Here is the code snippet that I am looking to convert:
// Create map instance
let chart = am4core.create("chartdivmap", am4maps.MapChart);
// Set map definition
chart.geodata = am4geodata_worldHigh;
// Set projection
chart.projection = new am4maps.projections.Miller();
// Center on the groups by default
chart.homeZoomLevel = 1.5;
chart.homeGeoPoint = {
longitude: 10,
latitude: 52
};
// Polygon series
let polygonSeries = chart.series.push(new am4maps.MapPolygonSeries());
polygonSeries.useGeodata = true;
var polygonTemplate = polygonSeries.mapPolygons.template;
polygonTemplate.tooltipText = "{name}";
polygonTemplate.fill = chart.colors.getIndex(0);
// Hover state
var hs = polygonTemplate.states.create("hover");
polygonTemplate.fill = am4core.color("#CCCCCC");
hs.properties.fill = am4core.color("#010101");
polygonTemplate.adapter.add("fill", function(fill, target) {
if (target.dataItem.dataContext && target.dataItem.dataContext.selected) {
return am4core.color("#666666");
}
return fill;
});
I attempted using let k:any = target;
and passing the variable like function(fill, target, k)
, trying to access the value with k.dataItem.dataContext.selected
, but this resulted in more errors.