chartjs / chartjs/Chart.js

Chart type mismatch in onClick and getRelativePosition

Open
#12,011 0 comments 0 reactions 0 assignees View on GitHub
type: bug type: types
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### Expected behavior

There shouldn't be any type error when writing something like this:

```ts
options: {
scales: {
y: {
beginAtZero: true,
},
},
onClick(event, elements, chart) {
const canvasPosition = getRelativePosition(event, chart);
const dataX = chart.scales.x.getValueForPixel(canvasPosition.x);
alert(dataX);
},
},
```

### Current behavior

This type error is present:

```
Argument of type 'Chart' is not assignable to parameter of type 'Chart'.
Type 'Chart' is missing the following properties from type 'Chart': _options, _aspectRatio, _layers, _metasets, and 40 more.typescript(2345)
(parameter) chart: Chart

```

### Reproducible sample

https://codesandbox.io/p/sandbox/reverent-noyce-x7wm8r

### Optional extra steps/info to reproduce

_No response_

### 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_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.