Angular ES6:不动产';选定的';不存在于类型';对象';

Angular ES6:不动产';选定的';不存在于类型';对象';,angular,typescript,amcharts,Angular,Typescript,Amcharts,从“AMcharts4代码笔预选区域”,我想将JS转换为ES6。然而,我犯了一个错误 错误TS2339:类型“Object”上不存在属性“selected” 我要转换的代码如下所示: // Create map instance let chart = am4core.create("chartdivmap", am4maps.MapChart); // Set map definition chart.geodata = am4geodata_worldHigh; // Set proje

从“AMcharts4代码笔预选区域”,我想将JS转换为ES6。然而,我犯了一个错误

错误TS2339:类型“Object”上不存在属性“selected”

我要转换的代码如下所示:

// 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;
});

我尝试了
让k:any=target并传递变量,如
函数(fill,target,k)
并尝试捕获值,如:
k.dataItem.dataContext.selected
,这给了我更多的错误。

您能尝试以下方法吗:

polygonTemplate.adapter.add("fill", function(fill, target) {
    const ctx = target.dataItem.dataContext as any;
    if (ctx && ctx.selected) {
        return am4core.color("#666666");
    }
    return fill;
});

这是编译错误还是运行时错误?我想是编译错误。ng serve向我展示了错误。但是如果我修改了代码,错误就会显示出来,但是项目无论如何都会运行,并显示预期的结果。我的目的是在命令行中隐藏错误,以便在生成创建过程中不会出现问题。请尝试使用
target.dataItem.dataContext&&(target.dataItem.dataContext,如有)。选中