amcharts4未使用角度6进行编译

时间:2018-11-21 16:18:44

标签: angular amcharts

包含amcharts4时,我在编译应用程序时遇到了麻烦。我只安装了amcharts4 npm软件包,并尝试在我创建的组件中使用它。我在CLI配置中缺少什么吗?

ERROR in node_modules/@amcharts/amcharts4/.internal/core/utils/Object.d.ts(60,117): error TS2536: Type 'Key' cannot be used to index type 'Object'.
node_modules/@amcharts/amcharts4/.internal/core/utils/Object.d.ts(67,109): error TS2536: Type 'Key' cannot be used to index type 'Object'.
node_modules/@amcharts/amcharts4/.internal/core/utils/Object.d.ts(76,116): error TS2536: Type 'Key' cannot be used to index type 'Object'.
node_modules/@amcharts/amcharts4/.internal/core/utils/Type.d.ts(25,32): error TS2304: Cannot find name 'Extract'.

我的打字稿:

import { Component, NgZone } from "@angular/core";
import * as am4core from "@amcharts/amcharts4/core";
import * as am4charts from "@amcharts/amcharts4/charts";
import am4themes_animated from "@amcharts/amcharts4/themes/animated";

am4core.useTheme(am4themes_animated);


@Component({
  selector: 'app-am-charts',
  templateUrl: './am-charts.component.html',
  styleUrls: ['./am-charts.component.css']
})
export class AmChartsComponent {

}

2 个答案:

答案 0 :(得分:1)

每个 this issue this newer closed issue和我们的angular integration documentation,请确保tsconfig.json中包含以下内容,因为AmCharts 4当前不支持严格模式:

{
    "compilerOptions": {
        "strictNullChecks": false,
        "strictFunctionTypes": false
    }
}

除此之外,请确保您至少使用TypeScript版本 2.7 2.8,而不是3.x,因为尚不支持。

答案 1 :(得分:0)

使用@ts-ignore注释忽略打字稿代码中的错误:

// @ts-ignore
import * as am4core from "@amcharts/amcharts4/core";

// @ts-ignore
import * as am4charts from "@amcharts/amcharts4/charts";

例如,将打字稿版本更新为最新版本:

npm install typescript@next --save

对我来说是"typescript": "^3.4.0-dev.20190220"