加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Typescript和Angular2-highcharts:’对象’类型上不存在属性’

发布时间:2020-12-17 18:10:44 所属栏目:安全 来源:网络整理
导读:当我尝试在Angular中实现以下plunkr时,我收到以下错误消息. Property 'series' does not exist on type 'Object'. http://plnkr.co/edit/OQSFSKisIIWAH0megy4d?p=preview 我安装了“angular2-highcharts”:“^ 0.5.5”, 并输入“@ types / highcharts”:“
当我尝试在Angular中实现以下plunkr时,我收到以下错误消息.

Property 'series' does not exist on type 'Object'.

http://plnkr.co/edit/OQSFSKisIIWAH0megy4d?p=preview

我安装了“angular2-highcharts”:“^ 0.5.5”,
并输入“@ types / highcharts”:“^ 5.0.5”,

任何帮助,将不胜感激.

解决方法

当您将其键入为Object时,编译器不知道this.options中是否存在属性系列.

要解决这个问题,你可以删除属性的输入(懒惰的方式):

class AppComponent {

    options: any;
}

或者您可以让编译器通过直接分配来从对象中推断出类型,以便正确输入this.options:

class AppComponent {

    options = {
        chart: {
            zoomType: 'xy'
        },series: ...
        // ...
    };
}

或者在界面中定义选项的类型:

interface Options {
    series: any[],// Should be typed to the shape of a series instead of `any`
    // and type other props like "chart","title"
}
class AppComponent {

    options: Options;

    constructor() {
        this.options = {
            chart: {
                zoomType: 'xy'
            },series: ...
            // ...
        };
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读