【问题标题】:amcharts4 is not compiling with angular 6amcharts4 未使用 Angular 6 进行编译
【发布时间】:2018-11-21 16:18:43
【问题描述】:

在包含 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 {

}

【问题讨论】:

    标签: angular amcharts


    【解决方案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,因为它尚不受支持。

    【讨论】:

    • 将其添加到 tsconfig.json 后,我仍然收到同样的问题
    • 我尝试使用 Angular cli v6.1.2 重新设置一个新应用程序,打字稿在 2.7.2 上,我仍然遇到同样的问题
    • 试试 TypeScript 2.8。我忘了我们将最低 TS 要求从 this other issue 提高了。
    【解决方案2】:

    使用@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"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-17
      • 2017-09-07
      • 1970-01-01
      • 1970-01-01
      • 2019-06-20
      • 1970-01-01
      相关资源
      最近更新 更多