Setting Chart.js scales y title gives compile time error " type '_DeepPartialObject"

Discussão em 'Angular' iniciado por devzero, Novembro 15, 2024.

  1. devzero

    devzero Guest

    I subscribe to data from the backend to fill my charts, when the data is received I would like to set some options so it goes like this:

    this.chart.config.options.scales.y.title.display = true;


    This give me a TS compile error


    Property 'title' does not exist on type '_DeepPartialObject<{ type: "linear"; } & CartesianScaleOptions & { beginAtZero: boolean; suggestedMin?: number; suggestedMax?: number; grace?: string | number; ticks: { format: NumberFormatOptions; precision: number; stepSize: number; count: number; }; }> | ... 4 more ... | _DeepPartialObject<...>'.
    ​

    I know I can cast it and it works, but is there a better way than having to cast it every time, working code:

    (this.chart.config.options.scales.y as CartesianScaleOptions).title.display = true;

    Continue reading...

Compartilhe esta Página