Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
downace opened this issue Feb 11, 2025 · 0 comments
Open

Comments

@downace
Copy link

downace commented Feb 11, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant