Skip to content

Conversation

anshukushwaha07
Copy link

This PR updates the TypeScript definition for Point to allow null values for x and y.

According to the Chart.js documentation, null is valid for skipped values in line charts. However, the current typings only accept number, which causes TypeScript errors when using null in datasets.

Before

export interface Point {
  x: number;
  y: number;
 }

After

export interface Point {
  x: number | null;
  y: number | null;
}

Example

new Chart<'line'>(ctx, {
  type: 'line',
  data: {
    datasets: [
      {
        data: [
          { x: 10, y: 20 },
          { x: 15, y: null }, //  now type checks correctly
          { x: 20, y: 10 }
        ]
      }
    ]
  }
});

Why this change is needed

  • Runtime behavior already supports null (point is skipped).
  • Docs confirm null is valid.
  • TypeScript definitions should align with runtime and docs.
  • Fixes TypeScript error: Type 'null' is not assignable to type 'number'

@LeeLenaleee LeeLenaleee added the type: types Typescript type changes label Sep 11, 2025
@LeeLenaleee LeeLenaleee added this to the Version 4.5.1 milestone Sep 11, 2025
Copy link
Author

@anshukushwaha07 anshukushwaha07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @LeeLenaleee , I’ve applied the suggested changes. Please re-review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: types Typescript type changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants