Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Types: Object data format should allow null values for `y` for Line Charts

Open downace opened this issue 1 year ago • 0 comments

Expected behavior

According to the docs, null values are allowed for skipped values for Line Charts. The following code should pass the type check:

import { Chart } from 'chart.js';

var ctx = document.getElementById("myChart") as HTMLCanvasElement;
var myChart = new Chart<'line'>(ctx, {
  // Config example from documentation
  type: 'line',
  data: {
    datasets: [{
      data: [{x: 10, y: 20}, {x: 15, y: null}, {x: 20, y: 10}]
      //                                ~~~~ null value here, should be ok
    }]
  }
});

Current behavior

TypeScript error: Type 'null' is not assignable to type 'number'.

Reproducible sample

https://www.typescriptlang.org/play/?ssl=11&ssc=4&pln=10&pc=4#code/JYWwDg9gTgLgBAbzgYQBYENZwL5wGZQQhwDkAxhrAHQBWAziQNwCwAUGwG6ZxkwAecALxwAJhDIBXEAFMAdjCoBzaTACiAG2kz5AIQCeASREAKAEQg9aTDFMBKOOjpwAEgBUAsgBlk6WVzoaWnIwLKxcUHAWVljCstIA7iiUMAA8JOrAcSQAfMa8fAA0iGxwcDB6YNIAXKQZWQUlougw6DUIjaUizY4qdDUA2u2spSNNLQMIfDUAjAAMRXo1AEyz2EWTMwCsCzWyEurqa4hTcCs7cHPYALodODfDOGzYtoxAA

Optional extra steps/info to reproduce

Generic type should be specified for Chart constructor: new Chart<'line'>(...). There are no errors without it.

Possible solution

No response

Context

No response

chart.js version

v4.4.7

Browser name and version

No response

Link to your project

No response

downace avatar Feb 11 '25 01:02 downace