chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
64.5k stars 11.89k forks source link

Default legend pie onClilck method type mismatch #11666

Open frenzymind opened 7 months ago

frenzymind commented 7 months ago

Expected behavior

Call method without type issue

Current behavior

LegendElement<keyof ChartTypeRegistry> is not assignable to parameter of type LegendElement<"pie">

Reproducible sample

codesandbox

Optional extra steps/info to reproduce

No response

Possible solution

I have to use type assertion: legend as LegendElement<'pie'>

Context

No response

chart.js version

chart.js v4.4.1 and types v2.9.41

Browser name and version

No response

Link to your project

No response

LeeLenaleee commented 7 months ago

Chart.js comes with build in types since V3. The types package is only for V2.

These types are not compatible. If you could try to remove the types package and see if that resolves the issue

frenzymind commented 7 months ago

I remove package, but error still exist. I update reproducible sample (remove types). There is no error for Chart.defaults.plugins.legend.onClick , just for Chart.overrides['pie'].plugins.legend.onClick
Type assertion fix error and code seems work correctly.